Changeset: fba3d719ba8c for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fba3d719ba8c Modified Files: monetdb5/modules/mal/txtsim.c sql/backends/monet5/rel_bin.c sql/backends/monet5/sql.c sql/backends/monet5/sql_execute.c sql/backends/monet5/sql_scenario.c sql/backends/monet5/sql_statistics.c sql/backends/monet5/sql_upgrades.c Branch: default Log Message:
A batch of GDKmalloc defense lines diffs (truncated from 370 to 300 lines): diff --git a/monetdb5/modules/mal/txtsim.c b/monetdb5/modules/mal/txtsim.c --- a/monetdb5/modules/mal/txtsim.c +++ b/monetdb5/modules/mal/txtsim.c @@ -23,6 +23,7 @@ #include "mal_exception.h" +// FIXME unchecked_malloc ATOMnil can return NULL #define RETURN_NIL_IF(b,t) \ if (b) {\ if (ATOMextern(t)) {\ diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -1033,7 +1033,11 @@ rel_parse_value(backend *be, char *query m->emode = emode; // FIXME unchecked_malloc GDKmalloc can return NULL b = (buffer*)GDKmalloc(sizeof(buffer)); + if (b == 0) + return sql_error(m, 02, MAL_MALLOC_FAIL); n = GDKmalloc(len + 1 + 1); + if (n == 0) + return sql_error(m, 02, MAL_MALLOC_FAIL); strncpy(n, query, len); query = n; query[len] = '\n'; @@ -2814,7 +2818,11 @@ sql_parse(backend *be, sql_allocator *sa m->emode = mode; b = (buffer*)GDKmalloc(sizeof(buffer)); + if (b == 0) + return sql_error(m, 02, MAL_MALLOC_FAIL); n = GDKmalloc(len + 1 + 1); + if (n == 0) + return sql_error(m, 02, MAL_MALLOC_FAIL); strncpy(n, query, len); query = n; query[len] = '\n'; diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -1849,20 +1849,36 @@ mvc_export_table_wrap( Client cntxt, Mal } l = strlen((char *) (*T)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(tsep = GDKmalloc(l + 1), *T, l); + tsep = GDKmalloc(l + 1); + if(tsep == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set1; + } + GDKstrFromStr(tsep, *T, l); l = 0; l = strlen((char *) (*R)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(rsep = GDKmalloc(l + 1), *R, l); + rsep = GDKmalloc(l + 1); + if(rsep == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set1; + } + GDKstrFromStr(rsep, *R, l); l = 0; l = strlen((char *) (*S)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(ssep = GDKmalloc(l + 1), *S, l); + ssep = GDKmalloc(l + 1); + if(ssep == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set1; + } + GDKstrFromStr(ssep, *S, l); l = 0; l = strlen((char *) (*N)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(ns = GDKmalloc(l + 1), *N, l); + ns = GDKmalloc(l + 1); + if(ns == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set1; + } + GDKstrFromStr(ns, *N, l); t->tsep = (char *) tsep; t->rsep = (char *) rsep; t->ssep = (char *) ssep; @@ -2028,20 +2044,36 @@ mvc_export_row_wrap( Client cntxt, MalBl } l = strlen((char *) (*T)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(tsep = GDKmalloc(l + 1), *T, l); + tsep = GDKmalloc(l + 1); + if(tsep == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set; + } + GDKstrFromStr(tsep, *T, l); l = 0; l = strlen((char *) (*R)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(rsep = GDKmalloc(l + 1), *R, l); + rsep = GDKmalloc(l + 1); + if(rsep == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set; + } + GDKstrFromStr(rsep, *R, l); l = 0; l = strlen((char *) (*S)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(ssep = GDKmalloc(l + 1), *S, l); + ssep = GDKmalloc(l + 1); + if(ssep == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set; + } + GDKstrFromStr(ssep, *S, l); l = 0; l = strlen((char *) (*N)); - // FIXME unchecked_malloc GDKmalloc can return NULL - GDKstrFromStr(ns = GDKmalloc(l + 1), *N, l); + ns = GDKmalloc(l + 1); + if(ns == 0){ + msg = createException(SQL, "sql.resultSet", MAL_MALLOC_FAIL); + goto wrapup_result_set; + } + GDKstrFromStr(ns, *N, l); t->tsep = (char *) tsep; t->rsep = (char *) rsep; t->ssep = (char *) ssep; @@ -2531,8 +2563,11 @@ mvc_import_table_wrap(Client cntxt, MalB /* overwrite other delimiters to the ones the FWF stream uses */ sprintf((char*) tsep, "%c", STREAM_FWF_FIELD_SEP); sprintf((char*) rsep, "%c", STREAM_FWF_RECORD_SEP); - if (!ssep) + if (!ssep) { ssep = GDKmalloc(2); + if(ssep == NULL) + throw(SQL, "sql.copy_from", MAL_MALLOC_FAIL); + } ssep[0] = 0; ss = stream_fwf_create(ss, ncol, widths, STREAM_FWF_FILLER); @@ -2595,7 +2630,7 @@ mvc_bin_import_table_wrap(Client cntxt, return msg; if ((s = mvc_bind_schema(m, sname)) == NULL) - throw(SQL, "sql.drop", "3F000!Schema missing"); + throw(SQL, "sql.import_table", "3F000!Schema missing"); t = mvc_bind_table(m, s, tname); if (!t) throw(SQL, "sql", "42S02!table %s not found", tname); @@ -2616,8 +2651,9 @@ mvc_bin_import_table_wrap(Client cntxt, if (ATOMvarsized(col->type.type->localtype) && col->type.type->localtype != TYPE_str) throw(SQL, "sql", "Failed to attach file %s", *getArgReference_str(stk, pci, i)); - // FIXME unchecked_malloc GDKmalloc can return NULL fn = GDKmalloc(flen + 1); + if(fn == NULL) + throw(SQL, "sql.attach", MAL_MALLOC_FAIL); GDKstrFromStr((unsigned char *) fn, (const unsigned char *) fname, flen); if (fn == NULL) throw(SQL, "sql", MAL_MALLOC_FAIL); @@ -2729,8 +2765,11 @@ zero_or_one(ptr ret, const bat *bid) _s = ATOMsize(ATOMtype(b->ttype)); if (ATOMextern(b->ttype)) { _s = ATOMlen(ATOMtype(b->ttype), p); - // FIXME unchecked_malloc GDKmalloc can return NULL memcpy(*(ptr *) ret = GDKmalloc(_s), p, _s); + if(ret == NULL){ + BBPunfix(b->batCacheid); + throw(SQL, "zero_or_one", MAL_MALLOC_FAIL); + } } else if (b->ttype == TYPE_bat) { bat bid = *(bat *) p; *(BAT **) ret = BATdescriptor(bid); @@ -2785,8 +2824,11 @@ SQLall(ptr ret, const bat *bid) _s = ATOMsize(ATOMtype(b->ttype)); if (ATOMextern(b->ttype)) { _s = ATOMlen(ATOMtype(b->ttype), p); - // FIXME unchecked_malloc GDKmalloc can return NULL memcpy(*(ptr *) ret = GDKmalloc(_s), p, _s); + if(ret == NULL){ + BBPunfix(b->batCacheid); + throw(SQL, "SQLall", MAL_MALLOC_FAIL); + } } else if (b->ttype == TYPE_bat) { bat bid = *(bat *) p; *(BAT **) ret = BATdescriptor(bid); diff --git a/sql/backends/monet5/sql_execute.c b/sql/backends/monet5/sql_execute.c --- a/sql/backends/monet5/sql_execute.c +++ b/sql/backends/monet5/sql_execute.c @@ -200,15 +200,19 @@ SQLexecutePrepared(Client c, backend *be cq *q= be->q; pci = getInstrPtr(mb, 0); - if (pci->argc >= MAXARG) + if (pci->argc >= MAXARG){ // FIXME unchecked_malloc GDKmalloc can return NULL argv = (ValPtr *) GDKmalloc(sizeof(ValPtr) * pci->argc); - else + if( argv == NULL) + throw(SQL,"sql.prepare",MAL_MALLOC_FAIL); + } else argv = argvbuffer; - if (pci->retc >= MAXARG) + if (pci->retc >= MAXARG){ argrec = (ValRecord *) GDKmalloc(sizeof(ValRecord) * pci->retc); - else + if( argrec == NULL) + throw(SQL,"sql.prepare",MAL_MALLOC_FAIL); + } else argrec = argrecbuffer; /* prepare the target variables */ @@ -405,7 +409,11 @@ SQLstatementIntern(Client c, str *expr, /* mimic a client channel on which the query text is received */ b = (buffer *) GDKmalloc(sizeof(buffer)); + if( b == NULL) + throw(SQL,"sql.statement",MAL_MALLOC_FAIL); n = GDKmalloc(len + 1 + 1); + if( n == NULL) + throw(SQL,"sql.statement",MAL_MALLOC_FAIL); strncpy(n, *expr, len); n[len] = '\n'; n[len + 1] = 0; diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -441,6 +441,9 @@ SQLinitClient(Client c) buffer *b = (buffer *) GDKmalloc(sizeof(buffer)); size_t len = strlen(sqlinit); bstream *fdin; + + if( b == NULL) + throw(SQL,"sql.initClient",MAL_MALLOC_FAIL); buffer_init(b, _STRDUP(sqlinit), len); fdin = bstream_create(buffer_rastream(b, "si"), b->len); diff --git a/sql/backends/monet5/sql_statistics.c b/sql/backends/monet5/sql_statistics.c --- a/sql/backends/monet5/sql_statistics.c +++ b/sql/backends/monet5/sql_statistics.c @@ -181,12 +181,20 @@ sql_analyze(Client cntxt, MalBlkPtr mb, GDKfree(maxval); // FIXME unchecked_malloc GDKmalloc can return NULL maxval = GDKmalloc(4); + if( maxval== NULL) + GDKfree(dquery); + throw(SQL, "analyze", MAL_MALLOC_FAIL); maxlen = 4; } if (minlen < 4) { GDKfree(minval); // FIXME unchecked_malloc GDKmalloc can return NULL minval = GDKmalloc(4); + if( minval== NULL){ + GDKfree(dquery); + GDKfree(maxval); + throw(SQL, "analyze", MAL_MALLOC_FAIL); + } minlen = 4; } if (tostr) { diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c --- a/sql/backends/monet5/sql_upgrades.c +++ b/sql/backends/monet5/sql_upgrades.c @@ -31,6 +31,9 @@ sql_update_hugeint(Client c, mvc *sql) char *buf = GDKmalloc(bufsize), *err = NULL; char *schema = stack_get_string(sql, "current_schema"); + if( buf== NULL) + throw(SQL, "sql_update_hugeint", MAL_MALLOC_FAIL); + pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n"); pos += snprintf(buf + pos, bufsize - pos, @@ -132,6 +135,8 @@ sql_update_epoch(Client c, mvc *m) int n = 0; sql_schema *s = mvc_bind_schema(m, "sys"); + if( buf== NULL) + throw(SQL, "sql_update_epoch", MAL_MALLOC_FAIL); pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n"); sql_find_subtype(&tp, "bigint", 0, 0); @@ -183,6 +188,8 @@ sql_update_jun2016(Client c, mvc *sql) node *n; sql_schema *s; + if( buf== NULL) + throw(SQL, "sql_update_jun2016", MAL_MALLOC_FAIL); s = mvc_bind_schema(sql, "sys"); pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n"); @@ -461,6 +468,8 @@ sql_update_geom(Client c, mvc *sql, int bufsize = strlen(geomupgrade) + 512; // FIXME unchecked_malloc GDKmalloc can return NULL _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list