[PATCH] libxl: Check for regcomp failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change libxlGetAutoballoonConf() function to return an int
for success/failure, and fail if regcomp fails.

Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---
 src/libxl/libxl_conf.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index fcb278b..a634476 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1014,21 +1014,28 @@ error:
     return -1;
 }
 
-static bool
-libxlGetAutoballoonConf(libxlDriverConfigPtr cfg)
+static int
+libxlGetAutoballoonConf(libxlDriverConfigPtr cfg, bool *autoballoon)
 {
     regex_t regex;
-    int ret;
+    int res;
+
+    if ((res = regcomp(&regex,
+                      "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
+                       REG_NOSUB | REG_EXTENDED)) != 0) {
+        char error[100];
+        regerror(res, &regex, error, sizeof(error));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to compile regex %s"),
+                       error);
 
-    ret = regcomp(&regex,
-            "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
-            REG_NOSUB | REG_EXTENDED);
-    if (ret)
-        return true;
+        return -1;
+    }
 
-    ret = regexec(&regex, cfg->verInfo->commandline, 0, NULL, 0);
+    res = regexec(&regex, cfg->verInfo->commandline, 0, NULL, 0);
     regfree(&regex);
-    return ret == REG_NOMATCH;
+    *autoballoon = res == REG_NOMATCH;
+    return 0;
 }
 
 libxlDriverConfigPtr
@@ -1098,7 +1105,8 @@ libxlDriverConfigNew(void)
     }
 
     /* setup autoballoon */
-    cfg->autoballoon = libxlGetAutoballoonConf(cfg);
+    if (libxlGetAutoballoonConf(cfg, &cfg->autoballoon) < 0)
+        goto error;
 
     return cfg;
 
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]