diff --git a/ChangeLog b/ChangeLog index d49218b5c5..eb9b036d47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jul 21 15:31:52 CEST 2008 Daniel Veillard + + * src/openvz_conf.c src/openvz_driver.c: patch from Evgeniy Sokolov + cleaning up integer string parsing. + Mon Jul 21 11:47:08 CEST 2008 Daniel Veillard * src/xen_unified.c: fix a leak in xenUnifiedOpen diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 8b920e00e4..743b6d4929 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -55,6 +55,7 @@ #include "uuid.h" #include "buf.h" #include "memory.h" +#include "util.h" static char *openvzLocateConfDir(void); static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml); @@ -127,17 +128,11 @@ struct openvz_vm int strtoI(const char *str) { - int base = 10; - char *endptr; int val; - val = (int) strtol(str, &endptr, base); + if (virStrToLong_i(str, NULL, 10, &val) < 0) + return 0 ; - /* Check for various possible errors */ - if ((endptr == str) /* "No digits were found" */ - ||((*endptr != '\0') - && (*endptr != ' ')) /*"Name contain characters other than integers" */ ) - return 0; return val; } diff --git a/src/openvz_driver.c b/src/openvz_driver.c index 2960354e01..e64d431c0c 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -449,7 +449,7 @@ openvzDomainCreateLinux(virConnectPtr conn, const char *xml, goto exit; } - sscanf(vmdef->name, "%d", &vm->vpsid); + vm->vpsid = strtoI(vmdef->name); vm->status = VIR_DOMAIN_RUNNING; ovz_driver.num_inactive--; ovz_driver.num_active++; @@ -487,7 +487,7 @@ openvzDomainCreate(virDomainPtr dom) return -1; } - sscanf(vm->vmdef->name, "%d", &vm->vpsid); + vm->vpsid = strtoI(vm->vmdef->name); vm->status = VIR_DOMAIN_RUNNING; ovz_driver.num_inactive --; ovz_driver.num_active ++; @@ -648,6 +648,7 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) { int veid, pid, outfd, errfd; int ret; char buf[32]; + char *endptr; const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL}; ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd); @@ -660,7 +661,11 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) { while(got < nids){ ret = openvz_readline(outfd, buf, 32); if(!ret) break; - sscanf(buf, "%d", &veid); + if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _("Could not parse VPS ID %s"), buf); + continue; + } ids[got] = veid; got ++; } @@ -679,6 +684,7 @@ static int openvzListDefinedDomains(virConnectPtr conn, int veid, pid, outfd, errfd, ret; char vpsname[OPENVZ_NAME_MAX]; char buf[32]; + char *endptr; const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S", NULL}; /* the -S options lists only stopped domains */ @@ -692,7 +698,11 @@ static int openvzListDefinedDomains(virConnectPtr conn, while(got < nnames){ ret = openvz_readline(outfd, buf, 32); if(!ret) break; - sscanf(buf, "%d\n", &veid); + if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _("Could not parse VPS ID %s"), buf); + continue; + } sprintf(vpsname, "%d", veid); names[got] = strdup(vpsname); got ++;