提交 3aab7f2d 编写于 作者: T Taisuke Yamada 提交者: Matthias Bolte

openvz: Fix regression in config file parsing

As reported by Diego Blanco in

  https://bugzilla.redhat.com/show_bug.cgi?id=702602

commit f0443765 which replaced openvz_readline to getline(3)
broke OpenVZ driver as it changed semantics of EOF-handling
when parsing OpenVZ configuration.

There're several other issues reported with current OpenVZ driver:

 #1: unclear error message when parsing "CPUS=" line
 #2: openvz driver goes into crashing loop
 #3: "NETIF=" line in configuration is not parsed correctly
 #4: aborts even when optional parameter is missing
 #5: there's a potential memory leak

This updated patch to fix #[145]. This patch does not fix #[23]
as I haven't verified these yet, but this at least got me to run
OpenVZ on libvirt once again.
上级 59953c38
...@@ -171,6 +171,7 @@ Patches have also been contributed by: ...@@ -171,6 +171,7 @@ Patches have also been contributed by:
Yufang Zhang <yuzhang@redhat.com> Yufang Zhang <yuzhang@redhat.com>
Supriya Kannery <supriyak@in.ibm.com> Supriya Kannery <supriyak@in.ibm.com>
Dirk Herrendoerfer <d.herrendoerfer@herrendoerfer.name> Dirk Herrendoerfer <d.herrendoerfer@herrendoerfer.name>
Taisuke Yamada <tai@rakugaki.org>
[....send patches to get your name here....] [....send patches to get your name here....]
......
...@@ -642,53 +642,45 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value) ...@@ -642,53 +642,45 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
/* /*
* value will be freed before a new value is assigned to it, the caller is * value will be freed before a new value is assigned to it, the caller is
* responsible for freeing it afterwards. * responsible for freeing it afterwards.
*
* Returns <0 on error, 0 if not found, 1 if found.
*/ */
static int static int
openvzReadConfigParam(const char *conf_file, const char *param, char **value) openvzReadConfigParam(const char *conf_file, const char *param, char **value)
{ {
char *line = NULL; char *line = NULL;
size_t line_size = 0; size_t line_size = 0;
ssize_t ret;
FILE *fp; FILE *fp;
int found = 0; int err = 0;
char *sf, *token; char *sf, *token, *saveptr = NULL;
char *saveptr = NULL;
value[0] = 0;
fp = fopen(conf_file, "r"); fp = fopen(conf_file, "r");
if (fp == NULL) if (fp == NULL)
return -1; return -1;
while (1) { VIR_FREE(*value);
ret = getline(&line, &line_size, fp); while (getline(&line, &line_size, fp) >= 0) {
if (ret <= 0) if (! STREQLEN(line, param, strlen(param)))
break; continue;
sf = line + strlen(param);
if (*sf++ != '=') continue;
saveptr = NULL; saveptr = NULL;
if (STREQLEN(line, param, strlen(param))) { if ((token = strtok_r(sf, "\"\t\n", &saveptr)) != NULL) {
sf = line;
sf += strlen(param);
if (sf[0] == '=' && sf[1] != '\0' ) {
sf++;
if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
VIR_FREE(*value); VIR_FREE(*value);
*value = strdup(token); *value = strdup(token);
if (value == NULL) { if (*value == NULL) {
ret = -1; err = 1;
break; break;
} }
found = 1; /* keep going - last entry wins */
}
}
} }
} }
VIR_FREE(line); VIR_FREE(line);
VIR_FORCE_FCLOSE(fp); VIR_FORCE_FCLOSE(fp);
if (ret == 0 && found) return err ? -1 : *value ? 1 : 0;
ret = 1;
return ret;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册