]> xenbits.xensource.com Git - libvirt.git/commitdiff
openvz: Use strtok_r instead of sscanf for VPS UUID parsing
authorMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 30 Mar 2010 14:34:43 +0000 (16:34 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 1 Apr 2010 10:53:41 +0000 (12:53 +0200)
Also free 2k stack space.

src/openvz/openvz_conf.c

index 7fc3cd10e47d7433344f195c3832db9cd7d115f8..d447eb90e272e6f69ea24b0b4a84bfb2b0e1d29d 100644 (file)
@@ -835,8 +835,9 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
 {
     char conf_file[PATH_MAX];
     char line[1024];
-    char uuidbuf[1024];
-    char iden[1024];
+    char *saveptr;
+    char *uuidbuf;
+    char *iden;
     int fd, ret;
     int retval = 0;
 
@@ -859,8 +860,10 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
             break;
         }
 
-        sscanf(line, "%s %s\n", iden, uuidbuf);
-        if(STREQ(iden, "#UUID:")) {
+        iden = strtok_r(line, " ", &saveptr);
+        uuidbuf = strtok_r(NULL, "\n", &saveptr);
+
+        if (iden != NULL && uuidbuf != NULL && STREQ(iden, "#UUID:")) {
             if (virStrcpy(uuidstr, uuidbuf, len) == NULL)
                 retval = -1;
             break;