]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
cls: check data before memcpy() it
authorNicolas PLANEL <nicolas.planel@enovance.com>
Tue, 26 Aug 2014 15:43:49 +0000 (11:43 -0400)
committerThomas Haller <thaller@redhat.com>
Wed, 27 Aug 2014 11:22:22 +0000 (13:22 +0200)
[thaller@redhat.com: I modified the condition "if (data && len)"
 in the original patch to just check "len > 0".
 Note that all call sites of meta_alloc() make sure to pass a
 valid data pointer with a non-zero length (anything else would
 be a bug). But indeed, calling memcpy with invalid src pointer
 is undefined behavior, even if len is zero.]

Signed-off-by: Thomas Haller <thaller@redhat.com>
lib/route/cls/ematch/meta.c

index 6249bb13586d588f3ae7d8b6632dc95e9c02e6d0..e33c405a98ee206e6d6b444056cbddb8f337f840 100644 (file)
@@ -51,7 +51,8 @@ static struct rtnl_meta_value *meta_alloc(uint8_t type, uint16_t id,
        value->mv_shift = shift;
        value->mv_len = len;
 
-       memcpy(value + 1, data, len);
+       if (len)
+               memcpy(value + 1, data, len);
 
        return value;
 }