]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
repodata_schema2id: fix heap-buffer-overflow in memcmp 344/head
authorZhipeng Xie <xiezhipeng1@huawei.com>
Tue, 6 Aug 2019 01:50:57 +0000 (09:50 +0800)
committerZhipeng Xie <xiezhipeng1@huawei.com>
Tue, 6 Aug 2019 02:13:38 +0000 (10:13 +0800)
When the length of last schema in data->schemadata is
less than length of input schema, we got a read overflow
in asan test.

Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
src/repodata.c

index 0c7a51f1ef079db9fac5734869824c992230aec3..3cae0fe4c36e47c5909a08e4f28364d1e0016601 100644 (file)
@@ -211,11 +211,13 @@ repodata_schema2id(Repodata *data, Id *schema, int create)
   cid = schematahash[h];
   if (cid)
     {
-      if (!memcmp(data->schemadata + data->schemata[cid], schema, len * sizeof(Id)))
+      if ((data->schemata[cid] + len <= data->schemadatalen) &&
+                         !memcmp(data->schemadata + data->schemata[cid], schema, len * sizeof(Id)))
         return cid;
       /* cache conflict, do a slow search */
       for (cid = 1; cid < data->nschemata; cid++)
-        if (!memcmp(data->schemadata + data->schemata[cid], schema, len * sizeof(Id)))
+        if ((data->schemata[cid] + len <= data->schemadatalen) &&
+                               !memcmp(data->schemadata + data->schemata[cid], schema, len * sizeof(Id)))
           return cid;
     }
   /* a new one */