Changeset: 2176b3caaca9 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/2176b3caaca9 Modified Files: sql/backends/monet5/dict.c sql/backends/monet5/for.c sql/backends/monet5/sql.c sql/backends/monet5/sql_statement.c Branch: default Log Message:
Defensive lines I missed diffs (163 lines): diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c --- a/sql/backends/monet5/dict.c +++ b/sql/backends/monet5/dict.c @@ -213,6 +213,12 @@ DICTcompress_col(Client cntxt, MalBlkPtr if (!sname || !tname || !cname) throw(SQL, "dict.compress", SQLSTATE(3F000) "dict compress: invalid column name"); + if (strNil(sname)) + throw(SQL, "dict.compress", SQLSTATE(42000) "Schema name cannot be NULL"); + if (strNil(tname)) + throw(SQL, "dict.compress", SQLSTATE(42000) "Table name cannot be NULL"); + if (strNil(cname)) + throw(SQL, "dict.compress", SQLSTATE(42000) "Column name cannot be NULL"); if ((msg = getBackendContext(cntxt, &be)) != MAL_SUCCEED) return msg; tr = be->mvc->session->tr; @@ -223,6 +229,9 @@ DICTcompress_col(Client cntxt, MalBlkPtr sql_table *t = find_sql_table(tr, s, tname); if (!t) throw(SQL, "dict.compress", SQLSTATE(3F000) "table '%s.%s' unknown", sname, tname); + if (!isTable(t)) + throw(SQL, "dict.compress", SQLSTATE(42000) "%s '%s' is not persistent", + TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name); sql_column *c = find_sql_column(t, cname); if (!c) throw(SQL, "dict.compress", SQLSTATE(3F000) "column '%s.%s.%s' unknown", sname, tname, cname); @@ -231,6 +240,8 @@ DICTcompress_col(Client cntxt, MalBlkPtr sqlstore *store = tr->store; BAT *b = store->storage_api.bind_col(tr, c, RDONLY), *o, *u; + if( b == NULL) + throw(SQL,"dict.compress", SQLSTATE(HY005) "Cannot access column descriptor"); msg = DICTcompress_intern(&o, &u, b, ordered, true, true); bat_destroy(b); diff --git a/sql/backends/monet5/for.c b/sql/backends/monet5/for.c --- a/sql/backends/monet5/for.c +++ b/sql/backends/monet5/for.c @@ -113,12 +113,16 @@ FORcompress_intern(char **comp_min_val, throw(SQL, "for.compress", SQLSTATE(3F000) "for compress: too large value spread for 'for' compression"); if ((max_val-min_val) < GDK_bte_max/2) { o = COLnew(b->hseqbase, TYPE_bte, cnt, PERSISTENT); + if (!o) + throw(SQL, "for.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); bte *ov = Tloc(o, 0); lng *iv = Tloc(b, 0); for(BUN i = 0; i<cnt; i++) ov[i] = (bte)(iv[i] - min_val); } else { o = COLnew(b->hseqbase, TYPE_sht, cnt, PERSISTENT); + if (!o) + throw(SQL, "for.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); sht *ov = Tloc(o, 0); lng *iv = Tloc(b, 0); for(BUN i = 0; i<cnt; i++) @@ -130,7 +134,10 @@ FORcompress_intern(char **comp_min_val, } if (!o) throw(SQL, "for.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); - *comp_min_val = GDKstrdup(buf); + if (!(*comp_min_val = GDKstrdup(buf))) { + bat_destroy(o); + throw(SQL, "for.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } BATsetcount(o, cnt); BATnegateprops(o); *r = o; @@ -151,6 +158,12 @@ FORcompress_col(Client cntxt, MalBlkPtr if (!sname || !tname || !cname) throw(SQL, "for.compress", SQLSTATE(3F000) "for compress: invalid column name"); + if (strNil(sname)) + throw(SQL, "for.compress", SQLSTATE(42000) "Schema name cannot be NULL"); + if (strNil(tname)) + throw(SQL, "for.compress", SQLSTATE(42000) "Table name cannot be NULL"); + if (strNil(cname)) + throw(SQL, "for.compress", SQLSTATE(42000) "Column name cannot be NULL"); if ((msg = getBackendContext(cntxt, &be)) != MAL_SUCCEED) return msg; tr = be->mvc->session->tr; @@ -161,6 +174,9 @@ FORcompress_col(Client cntxt, MalBlkPtr sql_table *t = find_sql_table(tr, s, tname); if (!t) throw(SQL, "for.compress", SQLSTATE(3F000) "table '%s.%s' unknown", sname, tname); + if (!isTable(t)) + throw(SQL, "for.compress", SQLSTATE(42000) "%s '%s' is not persistent", + TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name); sql_column *c = find_sql_column(t, cname); if (!c) throw(SQL, "for.compress", SQLSTATE(3F000) "column '%s.%s.%s' unknown", sname, tname, cname); @@ -171,6 +187,8 @@ FORcompress_col(Client cntxt, MalBlkPtr sqlstore *store = tr->store; BAT *b = store->storage_api.bind_col(tr, c, RDONLY), *o = NULL; + if( b == NULL) + throw(SQL,"for.compress", SQLSTATE(HY005) "Cannot access column descriptor"); char *comp_min_val = NULL; msg = FORcompress_intern(&comp_min_val, &o, b); @@ -181,8 +199,8 @@ FORcompress_col(Client cntxt, MalBlkPtr bat_destroy(o); throw(SQL, "for.compress", SQLSTATE(HY013) "alter_storage failed"); } + GDKfree(comp_min_val); bat_destroy(o); } - GDKfree(comp_min_val); return msg; } 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 @@ -5077,6 +5077,12 @@ SQLstr_column_vacuum(Client cntxt, MalBl sql_table *t = NULL; sql_column *c = NULL; + if (strNil(sname)) + throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "Schema name cannot be NULL"); + if (strNil(tname)) + throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "Table name cannot be NULL"); + if (strNil(cname)) + throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "Column name cannot be NULL"); if ((s = mvc_bind_schema(m, sname)) == NULL) throw(SQL, "sql.str_column_vacuum", SQLSTATE(3F000) "Invalid or missing schema %s",sname); if ((t = mvc_bind_table(m, s, tname)) == NULL) @@ -5189,6 +5195,12 @@ SQLstr_column_auto_vacuum(Client cntxt, sql_table *t = NULL; sql_column *c = NULL; + if (strNil(sname)) + throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Schema name cannot be NULL"); + if (strNil(tname)) + throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Table name cannot be NULL"); + if (strNil(cname)) + throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Column name cannot be NULL"); if ((s = mvc_bind_schema(m, sname)) == NULL) throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(3F000) "Invalid or missing schema %s",sname); if ((t = mvc_bind_table(m, s, tname)) == NULL) @@ -5234,6 +5246,12 @@ SQLstr_column_stop_vacuum(Client cntxt, sql_table *t = NULL; sql_column *c = NULL; + if (strNil(sname)) + throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Schema name cannot be NULL"); + if (strNil(tname)) + throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Table name cannot be NULL"); + if (strNil(cname)) + throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Column name cannot be NULL"); if ((s = mvc_bind_schema(m, sname)) == NULL) throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(3F000) "Invalid or missing schema %s",sname); if ((t = mvc_bind_table(m, s, tname)) == NULL) diff --git a/sql/backends/monet5/sql_statement.c b/sql/backends/monet5/sql_statement.c --- a/sql/backends/monet5/sql_statement.c +++ b/sql/backends/monet5/sql_statement.c @@ -584,6 +584,8 @@ stmt_bat(backend *be, sql_column *c, int sql_trans *tr = be->mvc->session->tr; sqlstore *store = tr->store; BAT *b = store->storage_api.bind_col(tr, c, QUICK); + if (!b) + return NULL; tt = b->ttype; } if (access == RD_UPD_ID) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list