]> xenbits.xensource.com Git - libvirt.git/commitdiff
Use VIR_STRNDUP instead of modifying the matched string
authorJán Tomko <jtomko@redhat.com>
Thu, 20 Mar 2014 12:14:11 +0000 (13:14 +0100)
committerJán Tomko <jtomko@redhat.com>
Wed, 26 Mar 2014 14:06:10 +0000 (15:06 +0100)
src/util/vircommand.c

index acf63b320e6d1cc1138157f12ede72bd43500d0c..0795935d99b97fb82aac3608887d9e46ee3d8f81 100644 (file)
@@ -2832,7 +2832,7 @@ virCommandRunRegex(virCommandPtr cmd,
         goto cleanup;
 
     for (k = 0; lines[k]; k++) {
-        char *p = NULL;
+        const char *p = NULL;
 
         /* ignore any command prefix */
         if (prefix)
@@ -2845,11 +2845,10 @@ virCommandRunRegex(virCommandPtr cmd,
             if (regexec(&reg[i], p, nvars[i]+1, vars, 0) != 0)
                 break;
 
-            /* NULL terminate each captured group in the line */
             for (j = 0; j < nvars[i]; j++) {
                 /* NB vars[0] is the full pattern, so we offset j by 1 */
-                p[vars[j+1].rm_eo] = '\0';
-                if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0)
+                if (VIR_STRNDUP(groups[ngroup++], p + vars[j+1].rm_so,
+                                vars[j+1].rm_eo - vars[j+1].rm_so) < 0)
                     goto cleanup;
             }