]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
lib/isc/pkc11.c: Fix possible NULL pointer dereference in push_attribute()
authorOndřej Surý <ondrej@sury.org>
Fri, 27 Sep 2019 10:01:30 +0000 (12:01 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 3 Oct 2019 07:50:27 +0000 (09:50 +0200)
(cherry picked from commit e8948fd9b4b8b188db2d51600dc01a46d57d4b5f)

lib/isc/pk11.c

index aaddac5c201f7a7582b7a6ef39503a0ce8d370c2..234a07e81f39a5882e10a6bea2e26a4b1785b448 100644 (file)
@@ -802,13 +802,17 @@ push_attribute(pk11_object_t *obj, isc_mem_t *mctx, size_t len) {
        CK_ATTRIBUTE *attr;
        CK_BYTE cnt = obj->attrcnt;
 
+       REQUIRE(old != NULL || cnt == 0);
+
        obj->repr = isc_mem_get(mctx, (cnt + 1) * sizeof(*attr));
        if (obj->repr == NULL) {
                obj->repr = old;
                return (NULL);
        }
        memset(obj->repr, 0, (cnt + 1) * sizeof(*attr));
-       memmove(obj->repr, old, cnt * sizeof(*attr));
+       if (old != NULL) {
+               memmove(obj->repr, old, cnt * sizeof(*attr));
+       }
        attr = obj->repr + cnt;
        attr->ulValueLen = (CK_ULONG) len;
        attr->pValue = isc_mem_get(mctx, len);