Mercurial > hg > sidinfo
changeset 331:e35e15f07c66
Add bounds checks for node index generation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 13 Jan 2020 13:11:29 +0200 |
parents | c8f52ea74803 |
children | 629876cc0540 |
files | sidlib.c |
diffstat | 1 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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);