Changeset: 84a870997647 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=84a870997647
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_scenario.c
sql/backends/monet5/sql_transaction.c
sql/include/sql_catalog.h
sql/server/rel_psm.c
sql/server/rel_select.c
sql/server/rel_semantic.c
sql/server/rel_sequence.c
sql/server/sql_mvc.c
sql/server/sql_mvc.h
sql/storage/store.c
sql/storage/store_dependency.c
sql/storage/store_sequence.c
sql/storage/store_sequence.h
Branch: default
Log Message:
Defensive lines for allocations
diffs (truncated from 816 to 300 lines):
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
@@ -3181,7 +3181,7 @@ sql_insert_key(backend *be, list *insert
}
}
-static void
+static int
sql_stack_add_inserted( mvc *sql, const char *name, sql_table *t, stmt
**updates)
{
/* Put single relation of updates and old values on to the stack */
@@ -3204,7 +3204,7 @@ sql_stack_add_inserted( mvc *sql, const
r = rel_table_func(sql->sa, NULL, NULL, exps, 2);
r->l = ti;
- stack_push_rel_view(sql, name, r);
+ return stack_push_rel_view(sql, name, r) ? 1 : 0;
}
static int
@@ -3220,15 +3220,17 @@ sql_insert_triggers(backend *be, sql_tab
for (n = t->triggers.set->h; n; n = n->next) {
sql_trigger *trigger = n->data;
- stack_push_frame(sql, "OLD-NEW");
+ if(!stack_push_frame(sql, "OLD-NEW"))
+ return 0;
if (trigger->event == 0 && trigger->time == time) {
stmt *s = NULL;
const char *n = trigger->new_name;
/* add name for the 'inserted' to the stack */
- if (!n) n = "new";
-
- sql_stack_add_inserted(sql, n, t, updates);
+ if (!n) n = "new";
+
+ if(!sql_stack_add_inserted(sql, n, t, updates))
+ return 0;
s = sql_parse(be, sql->sa, trigger->statement,
m_instantiate);
if (!s)
@@ -4096,7 +4098,7 @@ update_idxs_and_check_keys(backend *be,
return idx_updates;
}
-static void
+static int
sql_stack_add_updated(mvc *sql, const char *on, const char *nn, sql_table *t,
stmt *tids, stmt **updates)
{
/* Put single relation of updates and old values on to the stack */
@@ -4132,8 +4134,9 @@ sql_stack_add_updated(mvc *sql, const ch
r->l = ti;
/* put single table into the stack with 2 names, needed for the psm
code */
- stack_push_rel_view(sql, on, r);
- stack_push_rel_view(sql, nn, rel_dup(r));
+ if(!stack_push_rel_view(sql, on, r) || !stack_push_rel_view(sql, nn,
rel_dup(r)))
+ return 0;
+ return 1;
}
static int
@@ -4149,7 +4152,8 @@ sql_update_triggers(backend *be, sql_tab
for (n = t->triggers.set->h; n; n = n->next) {
sql_trigger *trigger = n->data;
- stack_push_frame(sql, "OLD-NEW");
+ if(!stack_push_frame(sql, "OLD-NEW"))
+ return 0;
if (trigger->event == 2 && trigger->time == time) {
stmt *s = NULL;
@@ -4159,8 +4163,9 @@ sql_update_triggers(backend *be, sql_tab
if (!n) n = "new";
if (!o) o = "old";
-
- sql_stack_add_updated(sql, o, n, t, tids, updates);
+
+ if(!sql_stack_add_updated(sql, o, n, t, tids, updates))
+ return 0;
s = sql_parse(be, sql->sa, trigger->statement,
m_instantiate);
if (!s)
return 0;
@@ -4348,7 +4353,7 @@ rel2bin_update(backend *be, sql_rel *rel
return cnt;
}
-static void
+static int
sql_stack_add_deleted(mvc *sql, const char *name, sql_table *t, stmt *tids)
{
/* Put single relation of updates and old values on to the stack */
@@ -4371,7 +4376,7 @@ sql_stack_add_deleted(mvc *sql, const ch
r = rel_table_func(sql->sa, NULL, NULL, exps, 2);
r->l = ti;
- stack_push_rel_view(sql, name, r);
+ return stack_push_rel_view(sql, name, r) ? 1 : 0;
}
static int
@@ -4387,16 +4392,18 @@ sql_delete_triggers(backend *be, sql_tab
for (n = t->triggers.set->h; n; n = n->next) {
sql_trigger *trigger = n->data;
- stack_push_frame(sql, "OLD-NEW");
+ if(!stack_push_frame(sql, "OLD-NEW"))
+ return 0;
if (trigger->event == 1 && trigger->time == time) {
stmt *s = NULL;
-
+
/* add name for the 'deleted' to the stack */
const char *o = trigger->old_name;
-
+
if (!o) o = "old";
-
- sql_stack_add_deleted(sql, o, t, tids);
+
+ if(!sql_stack_add_deleted(sql, o, t, tids))
+ return 0;
s = sql_parse(be, sql->sa, trigger->statement,
m_instantiate);
if (!s)
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
@@ -899,7 +899,8 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
/* keep copy of signature and relational expression */
snprintf(buf, BUFSIZ, "%s %s", *sig, *expr);
- stack_push_frame(m, NULL);
+ if(!stack_push_frame(m, NULL))
+ return createException(SQL,"RAstatement2",SQLSTATE(HY001)
MAL_MALLOC_FAIL);
ops = sa_list(m->sa);
while (c && *c && !isspace((unsigned char) *c)) {
char *vnme = c, *tnme;
@@ -932,7 +933,8 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
append(ops, exp_atom_ref(m->sa, nr, &t));
sql_set_arg(m, nr, a);
} else {
- stack_push_var(m, vnme+1, &t);
+ if(!stack_push_var(m, vnme+1, &t))
+ return
createException(SQL,"RAstatement2",SQLSTATE(HY001) MAL_MALLOC_FAIL);
append(ops, exp_var(m->sa, sa_strdup(m->sa, vnme+1),
&t, m->frame));
}
c = strchr(p, (int)',');
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
@@ -281,9 +281,11 @@ SQLinit(void)
return MAL_SUCCEED;
}
-#define SQLglobal(name, val) \
- stack_push_var(sql, name, &ctype); \
- stack_set_var(sql, name, VALset(&src, ctype.type->localtype, val));
+#define SQLglobal(name, val, failure) \
+ if(stack_push_var(sql, name, &ctype))
\
+ stack_set_var(sql, name, VALset(&src, ctype.type->localtype,
val)); \
+ else
\
+ failure++;
\
#define NR_GLOBAL_VARS 10
/* NR_GLOBAL_VAR should match exactly the number of variables created
@@ -298,37 +300,38 @@ global_variables(mvc *sql, char *user, c
bit F = FALSE;
ValRecord src;
str opt;
+ int failure = 0;
typename = "int";
sql_find_subtype(&ctype, typename, 0, 0);
- SQLglobal("debug", &sql->debug);
- SQLglobal("cache", &sql->cache);
+ SQLglobal("debug", &sql->debug, failure);
+ SQLglobal("cache", &sql->cache, failure);
typename = "varchar";
sql_find_subtype(&ctype, typename, 1024, 0);
- SQLglobal("current_schema", schema);
- SQLglobal("current_user", user);
- SQLglobal("current_role", user);
+ SQLglobal("current_schema", schema, failure);
+ SQLglobal("current_user", user, failure);
+ SQLglobal("current_role", user, failure);
/* inherit the optimizer from the server */
opt = GDKgetenv("sql_optimizer");
if (!opt)
opt = "default_pipe";
- SQLglobal("optimizer", opt);
+ SQLglobal("optimizer", opt, failure);
typename = "sec_interval";
sql_find_subtype(&ctype, typename, inttype2digits(ihour, isec), 0);
- SQLglobal("current_timezone", &sec);
+ SQLglobal("current_timezone", &sec, failure);
typename = "boolean";
sql_find_subtype(&ctype, typename, 0, 0);
- SQLglobal("history", &F);
+ SQLglobal("history", &F, failure);
typename = "bigint";
sql_find_subtype(&ctype, typename, 0, 0);
- SQLglobal("last_id", &sql->last_id);
- SQLglobal("rowcnt", &sql->rowcnt);
- return 0;
+ SQLglobal("last_id", &sql->last_id, failure);
+ SQLglobal("rowcnt", &sql->rowcnt, failure);
+ return failure;
}
#define TRANS_ABORTED SQLSTATE(25005) "Current transaction is aborted (please
ROLLBACK)\n"
@@ -464,17 +467,18 @@ SQLinitClient(Client c)
m = mvc_create(c->idx, 0, SQLdebug, c->fdin, c->fdout);
if( m == NULL)
throw(SQL,"sql.initClient",SQLSTATE(HY001)
MAL_MALLOC_FAIL);
- global_variables(m, "monetdb", "sys");
+ if(global_variables(m, "monetdb", "sys"))
+ throw(SQL,"sql.initClient",SQLSTATE(HY001)
MAL_MALLOC_FAIL);
if (isAdministrator(c) || strcmp(c->scenario, "msql") == 0)
/* console should return everything */
m->reply_size = -1;
be = (void *) backend_create(m, c);
if( be == NULL)
- throw(SQL,"sql.init", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ throw(SQL,"sql.initClient", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
} else {
be = c->sqlcontext;
m = be->mvc;
if(mvc_reset(m, c->fdin, c->fdout, SQLdebug, NR_GLOBAL_VARS) <
0)
- throw(SQL,"sql.init", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ throw(SQL,"sql.initClient", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
backend_reset(be);
}
if (m->session->tr)
@@ -1145,16 +1149,20 @@ SQLparser(Client c)
if ((!caching(m) || !cachable(m, r)) && m->emode != m_prepare) {
char *q = query_cleaned(QUERY(m->scanner));
-
- /* Query template should not be cached */
- scanner_query_processed(&(m->scanner));
+ if(!q) {
+ err = 1;
+ msg = createException(PARSE, "SQLparser",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ } else {
+ /* Query template should not be cached */
+ scanner_query_processed(&(m->scanner));
- err = 0;
- if (backend_callinline(be, c) < 0 ||
- backend_dumpstmt(be, c->curprg->def, r, 1, 0, q) <
0)
- err = 1;
- else opt = 1;
- GDKfree(q);
+ err = 0;
+ if (backend_callinline(be, c) < 0 ||
+ backend_dumpstmt(be, c->curprg->def, r,
1, 0, q) < 0)
+ err = 1;
+ else opt = 1;
+ GDKfree(q);
+ }
} else {
/* Add the query tree to the SQL query cache
* and bake a MAL program for it.
diff --git a/sql/backends/monet5/sql_transaction.c
b/sql/backends/monet5/sql_transaction.c
--- a/sql/backends/monet5/sql_transaction.c
+++ b/sql/backends/monet5/sql_transaction.c
@@ -36,10 +36,10 @@
#include <orderidx.h>
#define initcontext() \
- if ((msg = getSQLContext(cntxt, mb, &sql, NULL)) != NULL)\
- return msg;\
- if ((msg = checkSQLContext(cntxt)) != NULL)\
- return msg; \
+ if ((msg = getSQLContext(cntxt, mb, &sql, NULL)) != NULL)\
+ return msg;\
+ if ((msg = checkSQLContext(cntxt)) != NULL)\
+ return msg; \
if (name && strcmp(name, str_nil) == 0)\
name = NULL;
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -58,6 +58,8 @@
#define NO_DEPENDENCY 0
#define HAS_DEPENDENCY 1
#define CICLE_DEPENDENCY 2
+#define DEPENDENCY_CHECK_ERROR 3
+#define DEPENDENCY_CHECK_OK 0
#define NO_TRIGGER 0
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list