libxl: Check for regcomp failure

Change libxlGetAutoballoonConf() function to return an int
for success/failure, and fail if regcomp fails.
This commit is contained in:
Jim Fehlig 2013-09-04 00:21:42 -06:00
parent 7e1cbd14bb
commit 3fed82daa4

View File

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