Changeset: a9f1353c4b65 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a9f1353c4b65
Modified Files:
monetdb5/mal/mal_authorize.c
monetdb5/modules/mal/wlc.c
sql/backends/monet5/sql_rank.c
sql/backends/monet5/vaults/netcdf/netcdf.c
Branch: Mar2018
Log Message:
More BAT descriptor checks
diffs (202 lines):
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -183,6 +183,8 @@ AUTHinitTables(const char *passwd) {
/* don't check this bat since we'll fix it below */
GDKdebug &= ~CHECKMASK;
user = BATdescriptor(bid);
+ if (user == NULL)
+ throw(MAL, "initTables.user", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
GDKdebug = dbg;
isNew = 0;
}
@@ -204,6 +206,8 @@ AUTHinitTables(const char *passwd) {
/* don't check this bat since we'll fix it below */
GDKdebug &= ~CHECKMASK;
pass = BATdescriptor(bid);
+ if (pass == NULL)
+ throw(MAL, "initTables.passwd", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
GDKdebug = dbg;
isNew = 0;
}
@@ -224,6 +228,8 @@ AUTHinitTables(const char *passwd) {
AUTHcommit();
} else {
duser = BATdescriptor(bid);
+ if (duser == NULL)
+ throw(MAL, "initTables.duser", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
isNew = 0;
}
assert(duser);
diff --git a/monetdb5/modules/mal/wlc.c b/monetdb5/modules/mal/wlc.c
--- a/monetdb5/modules/mal/wlc.c
+++ b/monetdb5/modules/mal/wlc.c
@@ -604,6 +604,10 @@ WLCdatashipping(Client cntxt, MalBlkPtr
str sch,tbl,col, msg = MAL_SUCCEED;
(void) mb;
b= BATdescriptor(bid);
+ if (b == NULL) {
+ msg = createException(MAL, "wlc.datashipping", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ goto finish;
+ }
assert(b);
// large BATs can also be re-created using the query.
@@ -651,6 +655,8 @@ WLCdatashipping(Client cntxt, MalBlkPtr
cntxt->wlc_kind = WLC_CATALOG;
}
finish:
+ if(b)
+ BBPunfix(b->batCacheid);
if(sch)
GDKfree(sch);
if(tbl)
@@ -776,6 +782,13 @@ WLCupdate(Client cntxt, MalBlkPtr mb, Ma
BAT *b, *bval;
b= BATdescriptor(stk->stk[getArg(pci,4)].val.bval);
bval= BATdescriptor(stk->stk[getArg(pci,5)].val.bval);
+ if(b == NULL || bval == NULL) {
+ if(b)
+ BBPunfix(b->batCacheid);
+ if(bval)
+ BBPunfix(bval->batCacheid);
+ throw(MAL, "wlr.update", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ }
if( b->ttype == TYPE_void)
o = b->tseqbase;
else
diff --git a/sql/backends/monet5/sql_rank.c b/sql/backends/monet5/sql_rank.c
--- a/sql/backends/monet5/sql_rank.c
+++ b/sql/backends/monet5/sql_rank.c
@@ -45,11 +45,15 @@ SQLdiff(Client cntxt, MalBlkPtr mb, MalS
c = b;
bid = getArgReference_bat(stk, pci, 2);
b = BATdescriptor(*bid);
+ if (!b) {
+ BBPunfix(c->batCacheid);
+ throw(SQL, "sql.rank", SQLSTATE(HY005) "Cannot
access column descriptor");
+ }
- cmp = ATOMcompare(b->ttype);
- it = bat_iterator(b);
+ cmp = ATOMcompare(b->ttype);
+ it = bat_iterator(b);
v = BUNtail(it, 0);
- bp = (bit*)Tloc(c, 0);
+ bp = (bit*)Tloc(c, 0);
for(i=0; i<cnt; i++, bp++, rp++) {
*rp = *bp;
diff --git a/sql/backends/monet5/vaults/netcdf/netcdf.c
b/sql/backends/monet5/vaults/netcdf/netcdf.c
--- a/sql/backends/monet5/vaults/netcdf/netcdf.c
+++ b/sql/backends/monet5/vaults/netcdf/netcdf.c
@@ -294,6 +294,10 @@ header: %s", nc_strerror(retval));
/* Read dimensions from NetCDF header and insert a row for each one
into netcdf_dims table */
dims = (char **)GDKzalloc(sizeof(char *) * ndims);
+ if (!dims) {
+ msg = createException(MAL, "netcdf.attach", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
+ goto finish;
+ }
for (didx = 0; didx < ndims; didx++){
if ((retval = nc_inq_dim(ncid, didx, dname, &dlen)) != 0)
return createException(MAL, "netcdf.attach", SQLSTATE(NC000)
"Cannot read dimension %d : %s", didx, nc_strerror(retval));
@@ -311,6 +315,10 @@ header: %s", nc_strerror(retval));
goto finish;
dims[didx] = GDKstrdup(dname);
+ if (!dims[didx]) {
+ msg = createException(MAL, "netcdf.attach",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ goto finish;
+ }
}
/* Read variables and attributes from the header and insert rows in
netcdf_vars, netcdf_vardims, and netcdf_attrs tables */
@@ -373,6 +381,12 @@ header: %s", nc_strerror(retval));
switch ( atype ) {
case NC_CHAR:
aval = (char *) GDKzalloc(alen + 1);
+ if (!aval) {
+ GDKfree(esc_str0);
+ GDKfree(esc_str1);
+ msg = createException(MAL,
"netcdf.attach", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ goto finish;
+ }
if ((retval =
nc_get_att_text(ncid,vidx,aname,aval)))
return createException(MAL,
"netcdf.attach",
SQLSTATE(NC000) "Cannot read attribute %s value: %s",
@@ -450,9 +464,14 @@ header: %s", nc_strerror(retval));
goto finish;
}
- switch ( atype ) {
+ switch ( atype ) {
case NC_CHAR:
aval = (char *) GDKzalloc(alen + 1);
+ if (!aval) {
+ GDKfree(esc_str0);
+ msg = createException(MAL, "netcdf.attach",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ goto finish;
+ }
if ((retval =
nc_get_att_text(ncid,NC_GLOBAL,aname,aval))) {
GDKfree(esc_str0);
if (dims != NULL ){
@@ -586,6 +605,8 @@ NCDFimportVarStmt(str *sciqlstmt, str *f
nc_close(ncid);
*sciqlstmt = GDKstrdup(buf);
+ if(*sciqlstmt == NULL)
+ return createException(MAL, "netcdf.importvar", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
return msg;
}
@@ -607,6 +628,8 @@ NCDFloadVar(bat **dim, bat *v, int ncid,
dim_bids = *dim;
dlen = (size_t *)GDKzalloc(sizeof(size_t) * vndims);
+ if (!dlen)
+ return createException(MAL, "netcdf.attach", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
for (i = 0; i < vndims; i++){
if ((retval = nc_inq_dimlen(ncid, vdims[i], &dlen[i])))
@@ -759,8 +782,15 @@ NCDFimportVariable(Client cntxt, MalBlkP
dname = (char **) GDKzalloc( sizeof(char *) * vndims);
if (dname == NULL)
throw(MAL, "netcdf.importvar", SQLSTATE(HY001) MAL_MALLOC_FAIL);
- for (i = 0; i < vndims; i++)
+ for (i = 0; i < vndims; i++) {
dname[i] = (char *) GDKzalloc(NC_MAX_NAME + 1);
+ if(!dname[i]) {
+ for (j = 0; j < i; j++)
+ GDKfree(dname[j]);
+ GDKfree(dname);
+ throw(MAL, "netcdf.importvar", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
+ }
+ }
snprintf(aname, 256, "%s%d", vname, fid);
@@ -825,6 +855,11 @@ NCDFimportVariable(Client cntxt, MalBlkP
}
vbat = BATdescriptor(vbatid);
+ if(vbat == NULL) {
+ GDKfree(dname);
+ GDKfree(dim_bids);
+ return createException(MAL, "netcdf.importvar", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ }
store_funcs.append_col(m->session->tr, col, vbat, TYPE_bat);
BBPunfix(vbatid);
BBPrelease(vbatid);
@@ -840,6 +875,11 @@ NCDFimportVariable(Client cntxt, MalBlkP
}
dimbat = BATdescriptor(dim_bids[i]);
+ if(dimbat == NULL) {
+ GDKfree(dname);
+ GDKfree(dim_bids);
+ return createException(MAL, "netcdf.importvar",
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
+ }
store_funcs.append_col(m->session->tr, col, dimbat, TYPE_bat);
BBPunfix(dim_bids[i]); /* phys. ref from BATdescriptor */
BBPrelease(dim_bids[i]); /* log. ref. from loadVar */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list