From: Matthew Dillon Date: Sat, 27 Dec 2008 23:37:09 +0000 (-0800) Subject: Allow the values for environment variables specified with -e to be X-Git-Tag: v2.3.0~197 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/a6d77ab55a7fcedd574778f9f91186740294ea37 Allow the values for environment variables specified with -e to be quoted. Note that shells may strip the quotes so using this feature may also require the use of backslashes. --- diff --git a/sys/platform/vkernel/platform/init.c b/sys/platform/vkernel/platform/init.c index 84f2246db5..7d37aa85ea 100644 --- a/sys/platform/vkernel/platform/init.c +++ b/sys/platform/vkernel/platform/init.c @@ -144,7 +144,9 @@ main(int ac, char **av) int bootOnDisk = -1; /* set below to vcd (0) or vkd (1) */ int c; int i; + int j; int n; + int isq; int real_vkernel_enable; int supports_sse; size_t vsize; @@ -179,17 +181,27 @@ main(int ac, char **av) case 'e': /* * name=value:name=value:name=value... + * name="value"... + * + * Allow values to be quoted but note that shells + * may remove the quotes, so using this feature + * to embed colons may require a backslash. */ n = strlen(optarg); + isq = 0; kern_envp = malloc(n + 2); - for (i = 0; i < n; ++i) { - if (optarg[i] == ':') - kern_envp[i] = 0; + for (i = j = 0; i < n; ++i) { + if (optarg[i] == '"') + isq ^= 1; + else if (optarg[i] == '\'') + isq ^= 2; + else if (isq == 0 && optarg[i] == ':') + kern_envp[j++] = 0; else - kern_envp[i] = optarg[i]; + kern_envp[j++] = optarg[i]; } - kern_envp[i++] = 0; - kern_envp[i++] = 0; + kern_envp[j++] = 0; + kern_envp[j++] = 0; break; case 's': boothowto |= RB_SINGLE;