Skip to content

fix(VM_Manager): fix gpf issues with snapshots and php 8.4#2537

Merged
limetech merged 1 commit intounraid:masterfrom
SimonFair:fix(VM_Manager)-snap-GPF-fix
Feb 4, 2026
Merged

fix(VM_Manager): fix gpf issues with snapshots and php 8.4#2537
limetech merged 1 commit intounraid:masterfrom
SimonFair:fix(VM_Manager)-snap-GPF-fix

Conversation

@SimonFair
Copy link
Contributor

@SimonFair SimonFair commented Jan 30, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced snapshot XML retrieval with fallback mechanism for improved reliability
    • Improved snapshot deletion process for greater stability

✏️ Tip: You can customize this high-level summary in your review settings.

@SimonFair SimonFair added the 7.3 label Jan 30, 2026
@github-actions
Copy link

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.01.30.0919
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2537/webgui-pr-2537.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates

📝 Modified Files:

Click to expand file list
emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2537, or run:

plugin remove webgui-pr-2537

🤖 This comment is automatically generated and will be updated with each new push to this PR.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

Walkthrough

The changes modify snapshot handling in the libvirt helpers by introducing a fallback XML retrieval mechanism that attempts filesystem access before invoking virsh commands, and replacing certain direct library calls with shell command execution for snapshot operations.

Changes

Cohort / File(s) Summary
Snapshot XML Retrieval & Deletion
emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php
Added fallback mechanism to obtain snapshot XML: attempts reading from /etc/libvirt/qemu/snapshot/{vm}/{name}.xml first, then falls back to virsh snapshot-dumpxml. Introduced snapshot_res boolean to branch logic. Removed explicit domain_snapshot_get_xml() call in valid XML path. Replaced domain_snapshot_delete() library call with virsh snapshot-delete command execution using proper escaping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A snapshot's tale, once simple and straight,
Now clever with fallbacks that make it first-rate!
From file to virsh, a dance so refined,
Robust little snapshot, resilient in mind.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing GPF (General Protection Fault) issues related to snapshots and PHP 8.4 compatibility in the VM Manager plugin.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php (1)

1889-1919: ⚠️ Potential issue | 🟠 Major

Sanitize snapshot path + validate XML before parsing.

$vm/$name are interpolated into a filesystem path without validation, enabling path traversal; additionally, any non-empty but invalid XML will make simplexml_load_string fail and later array indexing will raise warnings and corrupt snapshot DB entries.

🛡️ Proposed hardening (path validation + XML sanity)
- $snapshot_xml = `@file_get_contents`("/etc/libvirt/qemu/snapshot/{$vm}/{$name}.xml");
+ // Restrict path segments to safe snapshot identifiers
+ if (!preg_match('/^[A-Za-z0-9._-]+$/', $vm) || !preg_match('/^[A-Za-z0-9._-]+$/', $name)) {
+     $snapshot_xml = '';
+ } else {
+     $snapshot_xml = `@file_get_contents`("/etc/libvirt/qemu/snapshot/{$vm}/{$name}.xml");
+ }
  if (empty($snapshot_xml)) {
      $snapshot_xml = trim(shell_exec("virsh snapshot-dumpxml ".escapeshellarg($vm)." ".escapeshellarg($name)." 2>/dev/null"));
  }
- $snapshot_res = !empty($snapshot_xml);
+ // Validate XML before use
+ if (!empty($snapshot_xml)) {
+     libxml_use_internal_errors(true);
+     $snapshot_obj = simplexml_load_string($snapshot_xml);
+     if ($snapshot_obj === false) {
+         $snapshot_xml = '';
+     }
+     libxml_clear_errors();
+ }
+ $snapshot_res = !empty($snapshot_xml);
🤖 Fix all issues with AI agents
In `@emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php`:
- Around line 2140-2142: The snapshot-delete exec call ignores the return status
and can leave stale metadata; inside the if ($ret != "noxml") block where
exec("virsh snapshot-delete ...", $snapDelOut, $snapDelRtn) is called, check
$snapDelRtn for non-zero, log the error including $snapDelRtn and
implode("\n",$snapDelOut) for details, and fail the operation (return false or
throw) or retry/cleanup as appropriate so you do not proceed as if metadata was
removed when it wasn't; ensure any subsequent code that removes or updates
metadata only runs when $snapDelRtn === 0.

Comment on lines +2140 to +2142
if ($ret != "noxml") {
exec("virsh snapshot-delete ".escapeshellarg($vm)." ".escapeshellarg($name)." --metadata 2>&1", $snapDelOut, $snapDelRtn);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle snapshot-delete failures.

exec() return status is ignored; if virsh snapshot-delete --metadata fails, you silently keep stale metadata.

✅ Suggested error handling
 if ($ret != "noxml") {
-    exec("virsh snapshot-delete ".escapeshellarg($vm)." ".escapeshellarg($name)." --metadata 2>&1", $snapDelOut, $snapDelRtn);
+    exec("virsh snapshot-delete ".escapeshellarg($vm)." ".escapeshellarg($name)." --metadata 2>&1", $snapDelOut, $snapDelRtn);
+    if ($snapDelRtn !== 0) {
+        if ($logging) qemu_log($vm, "snapshot-delete failed: ".implode("\n", $snapDelOut));
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ($ret != "noxml") {
exec("virsh snapshot-delete ".escapeshellarg($vm)." ".escapeshellarg($name)." --metadata 2>&1", $snapDelOut, $snapDelRtn);
}
if ($ret != "noxml") {
exec("virsh snapshot-delete ".escapeshellarg($vm)." ".escapeshellarg($name)." --metadata 2>&1", $snapDelOut, $snapDelRtn);
if ($snapDelRtn !== 0) {
if ($logging) qemu_log($vm, "snapshot-delete failed: ".implode("\n", $snapDelOut));
}
}
🤖 Prompt for AI Agents
In `@emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php` around lines
2140 - 2142, The snapshot-delete exec call ignores the return status and can
leave stale metadata; inside the if ($ret != "noxml") block where exec("virsh
snapshot-delete ...", $snapDelOut, $snapDelRtn) is called, check $snapDelRtn for
non-zero, log the error including $snapDelRtn and implode("\n",$snapDelOut) for
details, and fail the operation (return false or throw) or retry/cleanup as
appropriate so you do not proceed as if metadata was removed when it wasn't;
ensure any subsequent code that removes or updates metadata only runs when
$snapDelRtn === 0.

@limetech limetech merged commit c9d2138 into unraid:master Feb 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants