]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: Avoid possible NULL dereference in virSysinfoParsePPCProcessor
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Mar 2017 12:01:21 +0000 (07:01 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 7 Mar 2017 18:25:03 +0000 (13:25 -0500)
commit15b881474b6cebca18f531a0512aeb0db3d9cd39
tree74c5f7e44095e5bf8ef3ba404a0f8e815f5adfc3
parent7744d99415d32f5aab37c567934907960109bea7
util: Avoid possible NULL dereference in virSysinfoParsePPCProcessor

Found by Coverity. Because there's an "if ((cur = strstr(base, "revision"))
 != NULL) {" followed by a "base = cur" coverity notes that 'base' could
then be NULL causing the return to the top of the "while ((tmp_base =
strstr(base, "processor")) != NULL) {" to have strstr deref a NULL 'base'
pointer because the setting of base at the bottom of the loop is unconditional.

Alter the code to set "base = cur" after processing each key. That will
"ensure" that base doesn't get set to NULL if both "cpu" and "revision"
do no follow a "processor".

While a /proc/cpuinfo file that has a "processor" key but with neither
a "cpu" nor a "revision" doesn't seem feasible, the code is written as if
it could happen, so we have to account for it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/util/virsysinfo.c