Changeset: e7ef3f132514 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e7ef3f132514
Modified Files:
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_listing.c
        monetdb5/modules/mal/inspect.c
        monetdb5/modules/mal/mdb.c
        sql/backends/monet5/sql.c
Branch: Mar2018
Log Message:

Check the result of instruction2str


diffs (181 lines):

diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -792,8 +792,12 @@ str runMALsequence(Client cntxt, MalBlkP
                                break;
                        }
                        w= instruction2str(mb, 0, pci, FALSE);
-                       ret = createException(MAL,"interpreter", "unkown 
operation:%s", w);
-                       GDKfree(w);
+                       if(w) {
+                               ret = createException(MAL,"interpreter", 
"unkown operation:%s", w);
+                               GDKfree(w);
+                       } else {
+                               ret = createException(MAL,"interpreter", 
"failed instruction2str");
+                       }
                        if (cntxt->qtimeout && GDKusec()- mb->starttime > 
cntxt->qtimeout){
                                ret= createException(MAL, "mal.interpreter", 
RUNTIME_QRY_TIMEOUT);
                                break;
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -546,7 +546,7 @@ str
 mal2str(MalBlkPtr mb, int first, int last)
 {
        str ps = NULL, *txt;
-       int i, *len, totlen = 0;
+       int i, *len, totlen = 0, j;
 
        txt = GDKmalloc(sizeof(str) * mb->stop);
        len = GDKmalloc(sizeof(int) * mb->stop);
@@ -568,11 +568,21 @@ mal2str(MalBlkPtr mb, int first, int las
 
                if ( txt[i])
                        totlen += len[i] = (int)strlen(txt[i]);
+               else {
+                       addMalException(mb,"mal2str: " MAL_MALLOC_FAIL);
+                       GDKfree(len);
+                       for (j = first; j < i; j++)
+                               GDKfree(txt[j]);
+                       GDKfree(txt);
+                       return NULL;
+               }
        }
        ps = GDKmalloc(totlen + mb->stop + 1);
        if( ps == NULL){
                addMalException(mb,"mal2str: " MAL_MALLOC_FAIL);
                GDKfree(len);
+               for (i = first; i < last; i++)
+                       GDKfree(txt[i]);
                GDKfree(txt);
                return NULL;
        }
@@ -604,6 +614,8 @@ printInstruction(stream *fd, MalBlkPtr m
        if ( ps ){
                mnstr_printf(fd, "%s%s", (flg & LIST_MAL_MAPI ? "=" : ""), ps);
                GDKfree(ps);
+       } else {
+               mnstr_printf(fd,"#failed instruction2str()");
        }
        mnstr_printf(fd, "\n");
 }
@@ -620,6 +632,8 @@ fprintInstruction(FILE *fd, MalBlkPtr mb
        if ( ps ){
                fprintf(fd, "%s%s", (flg & LIST_MAL_MAPI ? "=" : ""), ps);
                GDKfree(ps);
+       } else {
+               fprintf(fd,"#failed instruction2str()");
        }
        fprintf(fd, "\n");
 }
@@ -660,6 +674,8 @@ void showMalBlkHistory(stream *out, MalB
                                mnstr_printf(out,"%s.%s[%2d] %s\n", 
                                        getModuleId(sig), 
getFunctionId(sig),j++,msg+3);
                                GDKfree(msg);
+                       } else {
+                               mnstr_printf(out,"#failed instruction2str()\n");
                        }
                } 
                m= m->history;
diff --git a/monetdb5/modules/mal/inspect.c b/monetdb5/modules/mal/inspect.c
--- a/monetdb5/modules/mal/inspect.c
+++ b/monetdb5/modules/mal/inspect.c
@@ -280,7 +280,8 @@ INSPECTgetDefinition(Client cntxt, MalBl
                str ps;
 
                for (i = 0; i < s->def->stop; i++) {
-                       ps = instruction2str(s->def,0, getInstrPtr(s->def, i), 
0);
+                       if((ps = instruction2str(s->def,0, getInstrPtr(s->def, 
i), 0)) == NULL)
+                               goto bailout;
                        if (BUNappend(b, ps + 1, FALSE) != GDK_SUCCEED) {
                                GDKfree(ps);
                                goto bailout;
@@ -321,6 +322,9 @@ INSPECTgetSignature(Client cntxt, MalBlk
                        char *c, *w;
 
                        ps = instruction2str(s->def, 0, getSignature(s), 0);
+                       if (ps == 0) {
+                               continue;
+                       }
                        c = strchr(ps, '(');
                        if (c == 0) {
                                GDKfree(ps);
@@ -461,7 +465,10 @@ INSPECTgetSource(Client cntxt, MalBlkPtr
                str ps;
 
                for (i = 0; i < s->def->stop; i++) {
-                       ps = instruction2str(s->def, 0, getInstrPtr(s->def, i), 
LIST_MAL_NAME );
+                       if((ps = instruction2str(s->def, 0, getInstrPtr(s->def, 
i), LIST_MAL_NAME )) == NULL) {
+                               GDKfree(buf);
+                               throw(MAL, "inspect.getSource", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+                       }
                        if( strlen(ps) >= lim-len){
                                /* expand the buffer */
                                char *bn;
diff --git a/monetdb5/modules/mal/mdb.c b/monetdb5/modules/mal/mdb.c
--- a/monetdb5/modules/mal/mdb.c
+++ b/monetdb5/modules/mal/mdb.c
@@ -399,6 +399,7 @@ MDBStkTrace(Client cntxt, MalBlkPtr m, M
        (void) cntxt;
        if ((msg = instruction2str(s->blk, s, p, LIST_MAL_DEBUG)) == NULL) {
                BBPreclaim(b);
+               BBPreclaim(bn);
                throw(MAL, "mdb.getStackTrace", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
        }
        len = strlen(msg);
@@ -406,6 +407,7 @@ MDBStkTrace(Client cntxt, MalBlkPtr m, M
        if ( buf == NULL){
                GDKfree(msg);
                BBPreclaim(b);
+               BBPreclaim(bn);
                throw(MAL,"mdb.setTrace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        }
        snprintf(buf,len+1024,"%s at %s.%s[%d]", msg,
@@ -416,12 +418,17 @@ MDBStkTrace(Client cntxt, MalBlkPtr m, M
                GDKfree(msg);
                GDKfree(buf);
                BBPreclaim(b);
+               BBPreclaim(bn);
                throw(MAL,"mdb.setTrace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        }
        GDKfree(msg);
 
        for (s = s->up, k++; s != NULL; s = s->up, k++) {
-               msg = instruction2str(s->blk, s, 
getInstrPtr(s->blk,s->pcup),LIST_MAL_DEBUG);
+               if ((msg = instruction2str(s->blk, s, 
getInstrPtr(s->blk,s->pcup),LIST_MAL_DEBUG)) == NULL){
+                       BBPunfix(b->batCacheid);
+                       BBPunfix(bn->batCacheid);
+                       throw(MAL,"mdb.setTrace", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+               }
                l = strlen(msg);
                if (l>len){
                        GDKfree(buf);
@@ -562,7 +569,10 @@ MDBgetDefinition(Client cntxt, MalBlkPtr
                throw(MAL, "mdb.getDefinition", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
 
        for (i = 0; i < m->stop; i++) {
-               ps = instruction2str(m,0, getInstrPtr(m, i), 1);
+               if((ps = instruction2str(m,0, getInstrPtr(m, i), 1)) == NULL) {
+                       BBPreclaim(b);
+                       throw(MAL, "mdb.getDefinition", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+               }
                if (BUNappend(b, ps, FALSE) != GDK_SUCCEED) {
                        GDKfree(ps);
                        BBPreclaim(b);
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
@@ -3809,9 +3809,13 @@ SQLargRecord(Client cntxt, MalBlkPtr mb,
        (void) cntxt;
        ret = getArgReference_str(stk, pci, 0);
        s = instruction2str(mb, stk, getInstrPtr(mb, 0), LIST_MAL_ALL);
+       if(s == NULL)
+               throw(SQL, "sql.argRecord", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        t = strchr(s, ' ');
        *ret = GDKstrdup(t ? t + 1 : s);
        GDKfree(s);
+       if(*ret == NULL)
+               throw(SQL, "sql.argRecord", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to