Skip to content

Commit

Permalink
Escape boot parameters to quoted space separated format of Parse_argv
Browse files Browse the repository at this point in the history
  • Loading branch information
ansiwen committed Oct 10, 2018
1 parent c994757 commit fb3d4c5
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions tenders/hvt/hvt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,32 @@

#include "hvt.h"

static void setup_cmdline(char *cmdline, int argc, char **argv)
static void push_cmdline(char c, size_t *pos, char *cmdline)
{
size_t cmdline_free = HVT_CMDLINE_SIZE;

cmdline[0] = 0;
if (*pos > HVT_CMDLINE_SIZE - 1) {
errx(1, "Guest command line too long (max=%d characters)",
HVT_CMDLINE_SIZE - 1);
}
cmdline[(*pos)++] = c;
}

static void setup_cmdline(char *cmdline, int argc, char **argv)
{
size_t pos = 0;
for (; *argv; argc--, argv++) {
size_t alen = snprintf(cmdline, cmdline_free, "%s%s", *argv,
(argc > 1) ? " " : "");
if (alen >= cmdline_free) {
errx(1, "Guest command line too long (max=%d characters)",
HVT_CMDLINE_SIZE - 1);
break;
push_cmdline('"', &pos, cmdline);
for (char *p = *argv; *p; p++) {
if (*p == '\\' || *p == '"') {
push_cmdline('\\', &pos, cmdline);
}
push_cmdline(*p, &pos, cmdline);
}
push_cmdline('"', &pos, cmdline);
if (argc > 1) {
push_cmdline(' ', &pos, cmdline);
}
cmdline_free -= alen;
cmdline += alen;
}
push_cmdline('\0', &pos, cmdline);
}

static void setup_modules(struct hvt *hvt)
Expand Down

0 comments on commit fb3d4c5

Please sign in to comment.