Changeset: 32367e7075d3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=32367e7075d3
Modified Files:
        sql/backends/monet5/sql.c
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_utils.c
Branch: Mar2018
Log Message:

BAT descriptor checks


diffs (truncated from 547 to 300 lines):

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
@@ -1430,7 +1430,11 @@ DELTAbat(bat *result, const bat *col, co
                BBPunfix(res->batCacheid);
                throw(MAL, "sql.delta", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
        }
-       u_id = BATdescriptor(*uid);
+       if ((u_id = BATdescriptor(*uid)) == NULL) {
+               BBPunfix(u_val->batCacheid);
+               BBPunfix(res->batCacheid);
+               throw(MAL, "sql.delta", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
+       }
        assert(BATcount(u_id) == BATcount(u_val));
        if (BATcount(u_id) &&
            BATreplace(res, u_id, u_val, TRUE) != GDK_SUCCEED) {
@@ -1443,7 +1447,10 @@ DELTAbat(bat *result, const bat *col, co
        BBPunfix(u_val->batCacheid);
 
        if (i && BATcount(i)) {
-               i = BATdescriptor(*ins);
+               if ((i = BATdescriptor(*ins)) == NULL) {
+                       BBPunfix(res->batCacheid);
+                       throw(MAL, "sql.delta", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+               }
                if (BATappend(res, i, NULL, TRUE) != GDK_SUCCEED) {
                        BBPunfix(res->batCacheid);
                        BBPunfix(i->batCacheid);
@@ -2855,7 +2862,10 @@ zero_or_one(ptr ret, const bat *bid)
                memcpy(*(ptr *) ret, p, _s);
        } else if (b->ttype == TYPE_bat) {
                bat bid = *(bat *) p;
-               *(BAT **) ret = BATdescriptor(bid);
+               if((*(BAT **) ret = BATdescriptor(bid)) == NULL){
+                       BBPunfix(b->batCacheid);
+                       throw(SQL, "zero_or_one", SQLSTATE(HY005) "Cannot 
access column descriptor");
+               }
        } else if (_s == 4) {
                *(int *) ret = *(int *) p;
        } else if (_s == 1) {
@@ -2915,7 +2925,10 @@ SQLall(ptr ret, const bat *bid)
                memcpy(*(ptr *) ret, p, _s);
        } else if (b->ttype == TYPE_bat) {
                bat bid = *(bat *) p;
-               *(BAT **) ret = BATdescriptor(bid);
+               if ((*(BAT **) ret = BATdescriptor(bid)) == NULL) {
+                       BBPunfix(b->batCacheid);
+                       throw(SQL, "all", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               }
        } else if (_s == 4) {
                *(int *) ret = *(int *) p;
        } else if (_s == 1) {
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -428,6 +428,8 @@ delta_update_val( sql_delta *bat, oid ri
        }
        if (bat->uibid && bat->uvbid) {
                BAT *ib = temp_descriptor(bat->ibid);
+               if(ib == NULL)
+                       return LOG_ERR;
 
                if (BATcount(ib) && ib->hseqbase <= rid) { 
                        if (void_inplace(ib, rid, upd, TRUE) != GDK_SUCCEED) {
@@ -437,6 +439,12 @@ delta_update_val( sql_delta *bat, oid ri
                } else {
                        BAT *ui = temp_descriptor(bat->uibid);
                        BAT *uv = temp_descriptor(bat->uvbid);
+                       if(ui == NULL || uv == NULL) {
+                               bat_destroy(ui);
+                               bat_destroy(uv);
+                               bat_destroy(ib);
+                               return LOG_ERR;
+                       }
 
                        if (isEbat(ui)){
                                temp_destroy(bat->uibid);
@@ -445,6 +453,11 @@ delta_update_val( sql_delta *bat, oid ri
                                        return LOG_ERR;
                                bat_destroy(ui);
                                ui = temp_descriptor(bat->uibid);
+                               if(ui == NULL) {
+                                       bat_destroy(uv);
+                                       bat_destroy(ib);
+                                       return LOG_ERR;
+                               }
                        }
                        if (isEbat(uv)){
                                temp_destroy(bat->uvbid);
@@ -453,6 +466,11 @@ delta_update_val( sql_delta *bat, oid ri
                                        return LOG_ERR;
                                bat_destroy(uv);
                                uv = temp_descriptor(bat->uvbid);
+                               if(uv == NULL) {
+                                       bat_destroy(ui);
+                                       bat_destroy(ib);
+                                       return LOG_ERR;
+                               }
                        }
                        if (BUNappend(ui, (ptr) &rid, TRUE) != GDK_SUCCEED ||
                            BUNappend(uv, (ptr) upd, TRUE) != GDK_SUCCEED) {
@@ -467,7 +485,8 @@ delta_update_val( sql_delta *bat, oid ri
                }
                bat_destroy(ib);
        } else {
-               b = temp_descriptor(bat->ibid);
+               if((b = temp_descriptor(bat->ibid)) == NULL)
+                       return LOG_ERR;
                if (void_inplace(b, rid, upd, TRUE) != GDK_SUCCEED) {
                        bat_destroy(b);
                        return LOG_ERR;
@@ -659,6 +678,8 @@ delta_append_bat( sql_delta *bat, BAT *i
                        bat_destroy(b);
                        if(bat->ibid != BID_NIL) {
                                b = temp_descriptor(bat->ibid);
+                               if (b == NULL)
+                                       return LOG_ERR;
                        } else {
                                return LOG_ERR;
                        }
@@ -690,6 +711,8 @@ delta_append_val( sql_delta *bat, void *
 #ifndef NDEBUG
        BAT *c = BBPquickdesc(bat->bid, 0);
 #endif
+       if(b == NULL)
+               return LOG_ERR;
 
        if (bat->cached) {
                bat_destroy(bat->cached);
@@ -702,6 +725,8 @@ delta_append_val( sql_delta *bat, void *
                bat->ibid = ebat2real(bat->ibid, bat->ibase);
                if(bat->ibid != BID_NIL) {
                        b = temp_descriptor(bat->ibid);
+                       if (b == NULL)
+                               return LOG_ERR;
                } else {
                        return LOG_ERR;
                }
@@ -914,6 +939,9 @@ delta_delete_bat( sql_dbat *bat, BAT *i 
 {
        BAT *b = temp_descriptor(bat->dbid);
 
+       if(!b)
+               return LOG_ERR;
+
        if (isEbat(b)) {
                temp_destroy(bat->dbid);
                bat->dbid = temp_copy(b->batCacheid, FALSE);
@@ -921,6 +949,8 @@ delta_delete_bat( sql_dbat *bat, BAT *i 
                        return LOG_ERR;
                bat_destroy(b);
                b = temp_descriptor(bat->dbid);
+               if(!b)
+                       return LOG_ERR;
        }
        assert(b->theap.storage != STORE_PRIV);
        if (BATappend(b, i, NULL, TRUE) != GDK_SUCCEED) {
@@ -946,6 +976,8 @@ delta_delete_val( sql_dbat *bat, oid rid
                        return LOG_ERR;
                bat_destroy(b);
                b = temp_descriptor(bat->dbid);
+               if (b == NULL)
+                       return LOG_ERR;
        }
        assert(b->theap.storage != STORE_PRIV);
        if (BUNappend(b, (ptr)&rid, TRUE) != GDK_SUCCEED) {
@@ -1261,6 +1293,9 @@ log_create_delta(sql_delta *bat)
                        temp_descriptor(bat->bid):
                        temp_descriptor(bat->ibid);
 
+       if (b == NULL)
+               return LOG_ERR;
+
        if (!bat->uibid) 
                bat->uibid = e_bat(TYPE_oid);
        if (!bat->uvbid) 
@@ -1285,6 +1320,9 @@ snapshot_new_persistent_bat(sql_trans *t
                        temp_descriptor(bat->bid):
                        temp_descriptor(bat->ibid);
 
+       if (b == NULL)
+               return LOG_ERR;
+
        (void)tr;
        /* snapshot large bats */
        bat_set_access(b, BAT_READ);
@@ -1301,6 +1339,11 @@ new_persistent_delta( sql_delta *bat, in
                BAT *b = temp_descriptor(bat->bid);
                BAT *i = temp_descriptor(bat->ibid);
 
+               if (b == NULL || i == NULL) {
+                       bat_destroy(b);
+                       bat_destroy(i);
+                       return LOG_ERR;
+               }
                bat->ibase = BATcount(b);
                bat->cnt = BATcount(b) + BATcount(i);
                bat->ucnt = 0;
@@ -1310,6 +1353,8 @@ new_persistent_delta( sql_delta *bat, in
                if (bat->ibid == BID_NIL) 
                        return LOG_ERR;
                i = temp_descriptor(bat->ibid);
+               if (i == NULL)
+                       return LOG_ERR;
                bat_set_access(i, BAT_READ);
                BAThseqbase(i, bat->ibase);
                bat_destroy(i);
@@ -1608,6 +1653,9 @@ log_create_dbat( sql_dbat *bat )
        BAT *b = temp_descriptor(bat->dbid);
        gdk_return ok;
 
+       if (b == NULL)
+               return LOG_ERR;
+
        ok = logger_add_bat(bat_logger, b, bat->dname);
        if (ok == GDK_SUCCEED)
                ok = log_bat_persists(bat_logger, b, bat->dname);
@@ -1629,6 +1677,9 @@ snapshot_create_del(sql_trans *tr, sql_t
        sql_dbat *bat = t->data;
        BAT *b = temp_descriptor(bat->dbid);
 
+       if (b == NULL)
+               return LOG_ERR;
+
        (void)tr;
        /* snapshot large bats */
        bat_set_access(b, BAT_READ);
@@ -1808,36 +1859,44 @@ clear_delta(sql_trans *tr, sql_delta *ba
        }
        if (bat->ibid) {
                b = temp_descriptor(bat->ibid);
-               sz += BATcount(b);
-               bat_clear(b);
-               BATcommit(b);
-               bat_destroy(b);
+               if(b) {
+                       sz += BATcount(b);
+                       bat_clear(b);
+                       BATcommit(b);
+                       bat_destroy(b);
+               }
        }
        if (bat->bid) {
                b = temp_descriptor(bat->bid);
-               sz += BATcount(b);
-               /* for transactions we simple switch to ibid only */
-               if (tr != gtrans) {
-                       temp_destroy(bat->bid);
-                       bat->bid = 0;
-               } else {
-                       bat_clear(b);
-                       BATcommit(b);
+               if(b) {
+                       sz += BATcount(b);
+                       /* for transactions we simple switch to ibid only */
+                       if (tr != gtrans) {
+                               temp_destroy(bat->bid);
+                               bat->bid = 0;
+                       } else {
+                               bat_clear(b);
+                               BATcommit(b);
+                       }
+                       bat->ibase = 0;
+                       bat_destroy(b);
                }
-               bat->ibase = 0;
-               bat_destroy(b);
        }
        if (bat->uibid) { 
                b = temp_descriptor(bat->uibid);
-               bat_clear(b);
-               BATcommit(b);
-               bat_destroy(b);
+               if(b) {
+                       bat_clear(b);
+                       BATcommit(b);
+                       bat_destroy(b);
+               }
        }
        if (bat->uvbid) { 
                b = temp_descriptor(bat->uvbid);
-               bat_clear(b);
-               BATcommit(b);
-               bat_destroy(b);
+               if(b) {
+                       bat_clear(b);
+                       BATcommit(b);
+                       bat_destroy(b);
+               }
        }
        bat->cnt = 0;
        bat->ucnt = 0;
@@ -2034,11 +2093,12 @@ clear_dbat(sql_trans *tr, sql_dbat *bat)
        }
        if (bat->dbid) {
                BAT *b = temp_descriptor(bat->dbid);
-
-               sz += BATcount(b);
-               bat_clear(b);
-               BATcommit(b);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to