]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nwfilter: fix NULL pointer check in virNWFilterSnoopReqNew
authorJán Tomko <jtomko@redhat.com>
Wed, 28 Nov 2012 13:34:45 +0000 (14:34 +0100)
committerOsier Yang <jyang@redhat.com>
Wed, 28 Nov 2012 16:00:39 +0000 (00:00 +0800)
This can't lead to a crash since virNWFilterSnoopReqNew is only called
with a static array as the argument, but if we check for NULL we should
do it right.

src/nwfilter/nwfilter_dhcpsnoop.c

index 807fd288258d5ce65890514857952305d9f44ae3..3321d0bf233f6f336a9722f948d053f96cd46d58 100644 (file)
@@ -573,12 +573,12 @@ virNWFilterSnoopReqNew(const char *ifkey)
 {
     virNWFilterSnoopReqPtr req;
 
-    if (ifkey == NULL || strlen(ifkey) != VIR_IFKEY_LEN - 1) {
+    if (ifkey == NULL || (ifkey && (strlen(ifkey) != VIR_IFKEY_LEN - 1))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("virNWFilterSnoopReqNew called with invalid "
                          "key \"%s\" (%zu)"),
                        ifkey ? ifkey : "",
-                       strlen(ifkey));
+                       ifkey ? strlen(ifkey) : 0);
         return NULL;
     }