]> xenbits.xensource.com Git - libvirt.git/commitdiff
xenconfig: check return value of regcomp
authorJim Fehlig <jfehlig@suse.com>
Tue, 12 Jan 2016 18:34:06 +0000 (11:34 -0700)
committerJim Fehlig <jfehlig@suse.com>
Tue, 12 Jan 2016 21:22:54 +0000 (14:22 -0700)
Commit ec63000a missed checking the return value of regcomp(),
which coverity promptly identified.

src/xenconfig/xen_sxpr.c

index a7a622f7899809971523cff03bcb815532c9f45e..cd6f2079d9d2225ec18850985b5ff772ac5c92e3 100644 (file)
@@ -325,6 +325,7 @@ xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec)
     char *trate = NULL;
     char *p;
     regex_t rec;
+    int err;
     char *suffix;
     unsigned long long tmp;
     int ret = -1;
@@ -336,7 +337,16 @@ xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec)
     if (p != NULL)
         *p = 0;
 
-    regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED|REG_NOSUB);
+    err = regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED|REG_NOSUB);
+    if (err != 0) {
+        char error[100];
+        regerror(err, &rec, error, sizeof(error));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to compile regular expression '%s': %s"),
+                       vif_bytes_per_sec_re, error);
+        goto cleanup;
+    }
+
     if (regexec(&rec, trate, 0, NULL, 0)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Invalid rate '%s' specified"), rate);