Changeset: 206896785e8c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=206896785e8c Modified Files: monetdb5/mal/mal_builder.c monetdb5/mal/mal_instruction.c Branch: Oct2020 Log Message:
Don't crash when a too long id is passed. diffs (265 lines): diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c --- a/monetdb5/mal/mal_builder.c +++ b/monetdb5/mal/mal_builder.c @@ -26,7 +26,8 @@ newAssignment(MalBlkPtr mb) InstrPtr q = newInstruction(mb,NULL,NULL); int k; - assert(q); + if (q == NULL) + return NULL; k = newTmpVariable(mb,TYPE_any); if (k < 0) { // construct an exception message to be passed to upper layers using ->errors @@ -46,7 +47,8 @@ newStmt(MalBlkPtr mb, const char *module str mName = putName(module), nName = putName(name); q = newInstruction(mb, mName, nName); - assert(q); + if (q == NULL) + return NULL; setDestVar(q, newTmpVariable(mb, TYPE_any)); if (getDestVar(q) < 0 ){ str msg = createException(MAL, "newStmt", "Can not allocate variable"); @@ -64,7 +66,8 @@ newStmtArgs(MalBlkPtr mb, const char *mo str mName = putName(module), nName = putName(name); q = newInstructionArgs(mb, mName, nName, args); - assert(q); + if (q == NULL) + return NULL; setDestVar(q, newTmpVariable(mb, TYPE_any)); if (getDestVar(q) < 0 || mb->errors != MAL_SUCCEED) { @@ -82,7 +85,8 @@ newReturnStmt(MalBlkPtr mb) InstrPtr q = newInstruction(mb, NULL, NULL); int k; - assert(q); + if (q == NULL) + return NULL; k = newTmpVariable(mb,TYPE_any); if (k < 0 ){ str msg = createException(MAL, "newReturnStmt", "Can not allocate return variable"); @@ -115,7 +119,8 @@ newComment(MalBlkPtr mb, const char *val ValRecord cst; int k; - assert(q); + if (q == NULL) + return NULL; q->token = REMsymbol; q->barrier = 0; cst.vtype= TYPE_str; @@ -143,7 +148,8 @@ newCatchStmt(MalBlkPtr mb, str nme) int i= findVariable(mb,nme); int k; - assert(q); + if (q == NULL) + return NULL; q->barrier = CATCHsymbol; if ( i< 0) { k = newVariable(mb, nme, strlen(nme),TYPE_str); @@ -166,7 +172,8 @@ newRaiseStmt(MalBlkPtr mb, str nme) int i= findVariable(mb,nme); int k; - assert(q); + if (q == NULL) + return NULL; q->barrier = RAISEsymbol; if ( i< 0) { k = newVariable(mb, nme, strlen(nme),TYPE_str); @@ -188,7 +195,8 @@ newExitStmt(MalBlkPtr mb, str nme) int i= findVariable(mb,nme); int k; - assert(q); + if (q == NULL) + return NULL; q->barrier = EXITsymbol; if ( i< 0) { k= newVariable(mb, nme,strlen(nme),TYPE_str); @@ -208,7 +216,8 @@ pushEndInstruction(MalBlkPtr mb) { InstrPtr q = newInstruction(mb,NULL, NULL); - assert(q); + if (q == NULL) + return NULL; q->token = ENDsymbol; q->barrier = 0; q->argc = 0; @@ -273,7 +282,8 @@ pushBte(MalBlkPtr mb, InstrPtr q, bte va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_bte; cst.val.btval= val; cst.len = 0; @@ -305,7 +315,8 @@ pushOid(MalBlkPtr mb, InstrPtr q, oid va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_oid; cst.val.oval= val; cst.len = 0; @@ -321,7 +332,8 @@ pushVoid(MalBlkPtr mb, InstrPtr q) int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_void; cst.val.oval= oid_nil; cst.len = 0; @@ -353,7 +365,8 @@ pushLng(MalBlkPtr mb, InstrPtr q, lng va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_lng; cst.val.lval= val; cst.len = 0; @@ -385,7 +398,8 @@ pushSht(MalBlkPtr mb, InstrPtr q, sht va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_sht; cst.val.shval= val; cst.len = 0; @@ -418,7 +432,8 @@ pushHge(MalBlkPtr mb, InstrPtr q, hge va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_hge; cst.val.hval= val; cst.len = 0; @@ -451,7 +466,8 @@ pushDbl(MalBlkPtr mb, InstrPtr q, dbl va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_dbl; cst.val.dval= val; cst.len = 0; @@ -483,7 +499,8 @@ pushFlt(MalBlkPtr mb, InstrPtr q, flt va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_flt; cst.val.fval= val; cst.len = 0; @@ -518,7 +535,8 @@ pushStr(MalBlkPtr mb, InstrPtr q, const int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_str; if ((cst.val.sval= GDKstrdup(Val)) == NULL) addMalException(mb, createException(MAL, "pushStr", "Can not allocate string variable")); @@ -553,7 +571,8 @@ pushBit(MalBlkPtr mb, InstrPtr q, bit va int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.vtype= TYPE_bit; cst.val.btval= val; cst.len = 0; @@ -569,7 +588,8 @@ pushNil(MalBlkPtr mb, InstrPtr q, int tp int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; cst.len = 0; if( !isaBatType(tpe) && tpe != TYPE_bat ) { assert(tpe < MAXATOMS); /* in particular, tpe!=TYPE_any */ @@ -612,7 +632,8 @@ pushNilType(MalBlkPtr mb, InstrPtr q, ch ValRecord cst; str msg; - assert(q); + if (q == NULL) + return NULL; idx= getAtomIndex(tpe, strlen(tpe), TYPE_any); if( idx < 0 || idx >= GDKatomcnt || idx >= MAXATOMS){ str msg = createException(MAL, "pushNilType", "Can not allocate type variable"); @@ -644,7 +665,8 @@ pushType(MalBlkPtr mb, InstrPtr q, int t ValRecord cst; str msg; - assert(q); + if (q == NULL) + return NULL; cst.vtype=TYPE_void; cst.val.oval= oid_nil; cst.len = 0; @@ -669,7 +691,8 @@ pushZero(MalBlkPtr mb, InstrPtr q, int t ValRecord cst; str msg; - assert(q); + if (q == NULL) + return NULL; cst.vtype=TYPE_int; cst.val.ival= 0; cst.len = 0; @@ -688,7 +711,8 @@ pushZero(MalBlkPtr mb, InstrPtr q, int t InstrPtr pushEmptyBAT(MalBlkPtr mb, InstrPtr q, int tpe) { - assert(q); + if (q == NULL) + return NULL; getModuleId(q) = getName("bat"); getFunctionId(q) = getName("new"); @@ -704,7 +728,8 @@ pushValue(MalBlkPtr mb, InstrPtr q, ValP int _t; ValRecord cst; - assert(q); + if (q == NULL) + return NULL; if (VALcopy(&cst, vr) == NULL) { str msg = createException(MAL, "pushValue", "Can not allocate variable"); addMalException(mb, msg); diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c --- a/monetdb5/mal/mal_instruction.c +++ b/monetdb5/mal/mal_instruction.c @@ -1273,7 +1273,7 @@ pushArgumentId(MalBlkPtr mb, InstrPtr p, size_t namelen = strlen(name); if ((v = newVariable(mb, name, namelen, getAtomIndex(name, namelen, TYPE_any))) < 0) { /* set the MAL block to erroneous and simply return without doing anything */ - mb->errors = createMalException(mb,0, TYPE, SQLSTATE(HY013) MAL_MALLOC_FAIL); + /* mb->errors already set */ return NULL; } } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list