]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
repodata_schema2id: fix heap-buffer-overflow in memcmp
authorZhipeng Xie <xiezhipeng1@huawei.com>
Tue, 6 Aug 2019 01:50:57 +0000 (09:50 +0800)
committerMichael Schroeder <mls@suse.de>
Thu, 20 May 2021 09:17:21 +0000 (11:17 +0200)
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 4ab5d188bf39d9ce1135e92d46aeac478f83611a..94c15ce0f5e883203e9550dac2c5515b1691a382 100644 (file)
@@ -205,11 +205,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 */