]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
virt: Fix off-by-one error when detecting hypervisor master
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jul 2023 09:08:48 +0000 (09:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Jul 2023 09:35:16 +0000 (09:35 +0000)
Reported-by: Mauro Condarelli <mc5686@mclink.it>
Fixes: #13155 - _fireinfo.detect_hypervisor() rises Segmentation fault
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_fireinfo/fireinfo.c

index 1d3f42434353bc42b91f7963ea37db4751744bfa..18edf34509b3f0385b84adeb9f6a9c5a6ded8952 100644 (file)
@@ -32,8 +32,8 @@ enum hypervisors {
        HYPER_KVM,
        HYPER_MSHV,
        HYPER_VMWARE,
+       // Must always be last
        HYPER_OTHER,
-       HYPER_LAST /* for loop - must be last*/
 };
 
 const char *hypervisor_ids[] = {
@@ -157,7 +157,7 @@ int detect_hypervisor(int *hypervisor) {
                *hypervisor = HYPER_OTHER;
 
                if (*sig.text) {
-                       for (int id = HYPER_NONE + 1; id < HYPER_LAST; id++) {
+                       for (int id = HYPER_NONE + 1; id < HYPER_OTHER; id++) {
                                if (strcmp(hypervisor_ids[id], sig.text) == 0) {
                                        *hypervisor = id;
                                        break;