# HG changeset patch # User Matti Hamalainen # Date 1578913889 -7200 # Node ID e35e15f07c66f0efc83c3f61720cc12b752ec817 # Parent c8f52ea748039bb8d17613721dfab3f1eefbb2d6 Add bounds checks for node index generation. diff -r c8f52ea74803 -r e35e15f07c66 sidlib.c --- a/sidlib.c Sun Jan 12 22:41:17 2020 +0200 +++ b/sidlib.c Mon Jan 13 13:11:29 2020 +0200 @@ -532,6 +532,9 @@ // int sidlib_sldb_build_index(SIDLibSLDB *dbh) { + if (dbh == NULL) + return THERR_NULLPTR; + // Free old index th_free_r(&(dbh->pindex)); @@ -544,6 +547,10 @@ SIDLibSLDBNode *node; size_t i; + // Check number of nodes against overflow + if (dbh->nnodes > UINTPTR_MAX / sizeof(SIDLibSTILNode *)) + return THERR_BOUNDS; + // Allocate memory for index-table dbh->pindex = (SIDLibSLDBNode **) th_malloc(sizeof(SIDLibSLDBNode *) * dbh->nnodes); if (dbh->pindex == NULL) @@ -1123,7 +1130,9 @@ SIDLibSTILNode *node; size_t i; - // XXX TODO Check number of nodes? + // Check number of nodes against overflow + if (dbh->nnodes > UINTPTR_MAX / sizeof(SIDLibSTILNode *)) + return THERR_BOUNDS; // Allocate memory for index-table dbh->pindex = (SIDLibSTILNode **) th_malloc(sizeof(SIDLibSTILNode *) * dbh->nnodes);