diff options
author | Jan Kiszka <jan.kiszka@web.de> | 2009-04-26 18:53:42 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-05-01 09:44:11 -0500 |
commit | ffad4116b96e29e0fbe892806f97c0a6c903d30d (patch) | |
tree | b16e3325d46f5a1637da46343e0772c09ebf4100 /vl.c | |
parent | 6f0437e8de95aebbd9e66af4d074c0d5119d86b7 (diff) |
net: Fix -net socket parameter checks
My commit ea053add700d8abe203cd79a9ffb082aee4eabc0 broke -net socket by
overwriting an intermediate buffer in the added check_param. Fix this
by switching check_param to automatic buffer allocation and release, ie.
callers no longer have to worry about providing a scratch buffer.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'vl.c')
-rw-r--r-- | vl.c | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -1866,29 +1866,45 @@ int get_param_value(char *buf, int buf_size, return 0; } -int check_params(char *buf, int buf_size, - const char * const *params, const char *str) +int check_params(const char * const *params, const char *str) { + int name_buf_size = 1; const char *p; - int i; + char *name_buf; + int i, len; + int ret = 0; + + for (i = 0; params[i] != NULL; i++) { + len = strlen(params[i]) + 1; + if (len > name_buf_size) { + name_buf_size = len; + } + } + name_buf = qemu_malloc(name_buf_size); p = str; while (*p != '\0') { - p = get_opt_name(buf, buf_size, p, '='); - if (*p != '=') - return -1; + p = get_opt_name(name_buf, name_buf_size, p, '='); + if (*p != '=') { + ret = -1; + break; + } p++; for(i = 0; params[i] != NULL; i++) - if (!strcmp(params[i], buf)) + if (!strcmp(params[i], name_buf)) break; - if (params[i] == NULL) - return -1; + if (params[i] == NULL) { + ret = -1; + break; + } p = get_opt_value(NULL, 0, p); if (*p != ',') break; p++; } - return 0; + + qemu_free(name_buf); + return ret; } /***********************************************************/ @@ -2241,7 +2257,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) "cache", "format", "serial", "werror", NULL }; - if (check_params(buf, sizeof(buf), params, str) < 0) { + if (check_params(params, str) < 0) { fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n", buf, str); return -1; |