vmd(8): fix specifying boot image in vm.conf
authordv <dv@openbsd.org>
Fri, 28 Apr 2023 21:22:20 +0000 (21:22 +0000)
committerdv <dv@openbsd.org>
Fri, 28 Apr 2023 21:22:20 +0000 (21:22 +0000)
Previous change to allow overriding changed the way we parsed and
stored the boot image path. The lifetime of the path was...much too
short. Heap allocate the kernel path.

Found by Mischa Peters.

ok mlarkin@

usr.sbin/vmd/parse.y

index ea91e74..09468e3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.y,v 1.66 2023/04/28 19:46:42 dv Exp $   */
+/*     $OpenBSD: parse.y,v 1.67 2023/04/28 21:22:20 dv Exp $   */
 
 /*
  * Copyright (c) 2007-2016 Reyk Floeter <reyk@openbsd.org>
@@ -477,7 +477,10 @@ vm_opts            : disable                       {
                                YYERROR;
                        }
                        free($2);
-                       kernel = path;
+                       kernel = malloc(sizeof(path));
+                       if (kernel == NULL)
+                               yyerror("malloc");
+                       memcpy(kernel, &path, sizeof(path));
                        vmc.vmc_flags |= VMOP_CREATE_KERNEL;
                }
                | BOOT DEVICE bootdevice        {