提交 c8eaba64 编写于 作者: E Eric Blake

sysinfo: fix parsing regression

Detected by gcc -O2, introduced in commit 532ce9c2.  If dmidecode
outputs a field unrecognized by the parsers, then the code would
dereference an uninitialized eol variable.

* src/util/sysinfo.c (virSysinfoParseBIOS)
(virSysinfoParseSystem, virSysinfoParseProcessor)
(virSysinfoParseMemory): Avoid uninitialized variable.
上级 8f338921
...@@ -130,7 +130,7 @@ virSysinfoRead(void) { ...@@ -130,7 +130,7 @@ virSysinfoRead(void) {
static char * static char *
virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret) virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret)
{ {
char *cur, *eol; char *cur, *eol = NULL;
if ((cur = strstr(base, "Vendor: ")) != NULL) { if ((cur = strstr(base, "Vendor: ")) != NULL) {
cur += 8; cur += 8;
...@@ -157,7 +157,7 @@ virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret) ...@@ -157,7 +157,7 @@ virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret)
goto no_memory; goto no_memory;
} }
return eol + 1; return eol ? eol + 1 : NULL;
no_memory: no_memory:
return NULL; return NULL;
...@@ -166,7 +166,7 @@ no_memory: ...@@ -166,7 +166,7 @@ no_memory:
static char * static char *
virSysinfoParseSystem(char *base, virSysinfoDefPtr ret) virSysinfoParseSystem(char *base, virSysinfoDefPtr ret)
{ {
char *cur, *eol; char *cur, *eol = NULL;
if ((base = strstr(base, "System Information")) == NULL) if ((base = strstr(base, "System Information")) == NULL)
return 0; return 0;
...@@ -215,7 +215,7 @@ virSysinfoParseSystem(char *base, virSysinfoDefPtr ret) ...@@ -215,7 +215,7 @@ virSysinfoParseSystem(char *base, virSysinfoDefPtr ret)
goto no_memory; goto no_memory;
} }
return eol + 1; return eol ? eol + 1 : NULL;
no_memory: no_memory:
return NULL; return NULL;
...@@ -229,6 +229,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret) ...@@ -229,6 +229,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
while((tmp_base = strstr(base, "Processor Information")) != NULL) { while((tmp_base = strstr(base, "Processor Information")) != NULL) {
base = tmp_base; base = tmp_base;
eol = NULL;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) { if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
goto no_memory; goto no_memory;
...@@ -313,6 +314,8 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret) ...@@ -313,6 +314,8 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
goto no_memory; goto no_memory;
} }
if (!eol)
break;
base = eol + 1; base = eol + 1;
} }
...@@ -330,6 +333,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret) ...@@ -330,6 +333,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
while ((tmp_base = strstr(base, "Memory Device")) != NULL) { while ((tmp_base = strstr(base, "Memory Device")) != NULL) {
base = tmp_base; base = tmp_base;
eol = NULL;
if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0) { if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0) {
goto no_memory; goto no_memory;
...@@ -411,6 +415,8 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret) ...@@ -411,6 +415,8 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
} }
next: next:
if (!eol)
break;
base = eol + 1; base = eol + 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册