[libvirt] [PATCH] sysinfo: fix illegal NULL return

If virSysinfoParse{BIOS,System,Processor,Memory}() can't find newline('\n'), these return NULL. This patch fixes this. Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp> --- src/util/sysinfo.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c index d32f7f0..a6e525b 100644 --- a/src/util/sysinfo.c +++ b/src/util/sysinfo.c @@ -131,7 +131,12 @@ static char * virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret) { char *cur, *eol = NULL; + char *tmp_base; + if ((tmp_base = strstr(base, "BIOS Information")) == NULL) + return base; + + base = tmp_base; if ((cur = strstr(base, "Vendor: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); @@ -157,7 +162,7 @@ virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret) goto no_memory; } - return eol ? eol + 1 : NULL; + return base + strlen("BIOS Information"); no_memory: return NULL; @@ -167,10 +172,12 @@ static char * virSysinfoParseSystem(char *base, virSysinfoDefPtr ret) { char *cur, *eol = NULL; + char *tmp_base; - if ((base = strstr(base, "System Information")) == NULL) - return 0; + if ((tmp_base = strstr(base, "System Information")) == NULL) + return base; + base = tmp_base; if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); @@ -215,7 +222,7 @@ virSysinfoParseSystem(char *base, virSysinfoDefPtr ret) goto no_memory; } - return eol ? eol + 1 : NULL; + return base + strlen("System Information"); no_memory: return NULL; @@ -314,9 +321,7 @@ virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret) goto no_memory; } - if (!eol) - break; - base = eol + 1; + base += strlen("Processor Information"); } return base; @@ -415,9 +420,7 @@ virSysinfoParseMemory(char *base, virSysinfoDefPtr ret) } next: - if (!eol) - break; - base = eol + 1; + base += strlen("Memory Device"); } return base; -- 1.7.1 -- Minoru Usui <usui@mxm.nes.nec.co.jp>

On 06/28/2011 10:33 PM, Minoru Usui wrote:
If virSysinfoParse{BIOS,System,Processor,Memory}() can't find newline('\n'), these return NULL. This patch fixes this.
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp> --- src/util/sysinfo.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c index d32f7f0..a6e525b 100644 --- a/src/util/sysinfo.c +++ b/src/util/sysinfo.c @@ -131,7 +131,12 @@ static char * virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret) { char *cur, *eol = NULL; + char *tmp_base;
+ if ((tmp_base = strstr(base, "BIOS Information")) == NULL) + return base; + + base = tmp_base; if ((cur = strstr(base, "Vendor: ")) != NULL) {
I simplified this to use one less local variable. ACK and push. diff --git i/src/util/sysinfo.c w/src/util/sysinfo.c index a6e525b..f4edde9 100644 --- i/src/util/sysinfo.c +++ w/src/util/sysinfo.c @@ -131,12 +131,11 @@ static char * virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret) { char *cur, *eol = NULL; - char *tmp_base; - if ((tmp_base = strstr(base, "BIOS Information")) == NULL) + if ((cur = strstr(base, "BIOS Information")) == NULL) return base; - base = tmp_base; + base = cur; if ((cur = strstr(base, "Vendor: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); @@ -172,12 +171,11 @@ static char * virSysinfoParseSystem(char *base, virSysinfoDefPtr ret) { char *cur, *eol = NULL; - char *tmp_base; - if ((tmp_base = strstr(base, "System Information")) == NULL) + if ((cur = strstr(base, "System Information")) == NULL) return base; - base = tmp_base; + base = cur; if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Minoru Usui