Re: [PATCH] tests: avoid null pointer dereference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/03/2011 10:42 AM, Daniel P. Berrange wrote:
> On Tue, May 03, 2011 at 10:38:00AM -0600, Eric Blake wrote:
>> Unlikely to hit in real life, but clang noticed it.
>>
>> * tests/commandtest.c (test4): Avoid unlink(NULL) on OOM.
>> ---
>>
>>  cleanup:
>>      virCommandFree(cmd);
>> -    unlink(pidfile);
>> +    if (pidfile)
>> +        unlink(pidfile);
>>      VIR_FREE(pidfile);
>>      return ret;
>>  }
> 
> ACK

Actually, clang found a couple more in the same file.  Here's what I
finally pushed:

diff --git c/tests/commandtest.c w/tests/commandtest.c
index fa0061c..caad698 100644
--- c/tests/commandtest.c
+++ w/tests/commandtest.c
@@ -78,7 +78,8 @@ static int checkoutput(const char *testname)
     ret = 0;

 cleanup:
-    unlink(actualname);
+    if (actualname)
+        unlink(actualname);
     VIR_FREE(actuallog);
     VIR_FREE(actualname);
     VIR_FREE(expectlog);
@@ -240,7 +241,8 @@ static int test4(const void *unused ATTRIBUTE_UNUSED)

 cleanup:
     virCommandFree(cmd);
-    unlink(pidfile);
+    if (pidfile)
+        unlink(pidfile);
     VIR_FREE(pidfile);
     return ret;
 }
@@ -703,7 +705,8 @@ static int test18(const void *unused ATTRIBUTE_UNUSED)

 cleanup:
     virCommandFree(cmd);
-    unlink(pidfile);
+    if (pidfile)
+        unlink(pidfile);
     VIR_FREE(pidfile);
     return ret;
 }


-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]