Changeset: 2850ec270fbd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2850ec270fbd
Modified Files:
        monetdb5/mal/mal_instruction.c
        monetdb5/modules/atoms/xml.c
        monetdb5/modules/mal/mal_io.c
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/sql_result.c
Branch: default
Log Message:

Added error checking, especially with atomFromStr/ATOMfromstr.


diffs (155 lines):

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
@@ -1276,8 +1276,7 @@ convertConstant(int type, ValPtr vr)
                ptr d = NULL;
                char *s = vr->val.sval;
 
-               ATOMfromstr(type, &d, &ll, vr->val.sval);
-               if (d == NULL) {
+               if (ATOMfromstr(type, &d, &ll, vr->val.sval) < 0 || d == NULL) {
                        VALinit(vr, type, ATOMnilptr(type));
                        throw(SYNTAX, "convertConstant", "parse error in '%s'", 
s);
                }
@@ -1415,8 +1414,7 @@ convertConstant(int type, ValPtr vr)
                        /* dump the non-string atom as string in w */
                        ATOMformat(vr->vtype, VALptr(vr), &w);
                        /* and try to parse it from string as the desired type 
*/
-                       ATOMfromstr(type, &d, &ll, w);
-                       if (d == 0) {
+                       if (ATOMfromstr(type, &d, &ll, w) < 0 || d == 0) {
                                VALinit(vr, type, ATOMnilptr(type));
                                GDKfree(w);
                                throw(SYNTAX, "convertConstant", "conversion 
error");
@@ -1427,8 +1425,7 @@ convertConstant(int type, ValPtr vr)
                                GDKfree(d);
                        GDKfree(w);
                } else {                                /* what we're 
converting from is a string */
-                       ATOMfromstr(type, &d, &ll, vr->val.sval);
-                       if (d == NULL) {
+                       if (ATOMfromstr(type, &d, &ll, vr->val.sval) < 0 || d 
== NULL) {
                                VALinit(vr, type, ATOMnilptr(type));
                                throw(SYNTAX, "convertConstant", "conversion 
error");
                        }
diff --git a/monetdb5/modules/atoms/xml.c b/monetdb5/modules/atoms/xml.c
--- a/monetdb5/modules/atoms/xml.c
+++ b/monetdb5/modules/atoms/xml.c
@@ -644,10 +644,18 @@ XMLfromString(str src, int *len, xml *x)
 {
        if (*x)
                GDKfree(*x);
-       if (strcmp(src, "nil") == 0)
+       if (strcmp(src, "nil") == 0) {
                *x = GDKstrdup(str_nil);
-       else
-               XMLstr2xml(x, &src);
+               if (*x == NULL)
+                       return -1;
+       } else {
+               char *err = XMLstr2xml(x, &src);
+               if (err != MAL_SUCCEED) {
+                       if (err != M5OutOfMemory)
+                               GDKfree(err);
+                       return -1;
+               }
+       }
        *len = (int) strlen(*x);
        return *len;
 }
diff --git a/monetdb5/modules/mal/mal_io.c b/monetdb5/modules/mal/mal_io.c
--- a/monetdb5/modules/mal/mal_io.c
+++ b/monetdb5/modules/mal/mal_io.c
@@ -706,12 +706,14 @@ IOimport(int *ret, int *bid, str *fnme)
        BAT *b;
        int (*hconvert) (const char *, int *, ptr *);
        int (*tconvert) (const char *, int *, ptr *);
+       int n;
        size_t bufsize = 2048;  /* NIELS:tmp change used to be 1024 */
        char *base, *cur, *end;
        char *buf;
        ptr h = 0, t = 0;
        int lh = 0, lt = 0;
        FILE *fp = fopen(*fnme, "r");
+       char msg[BUFSIZ];
 
        if ((b = BATdescriptor(*bid)) == NULL) {
                if (fp)
@@ -818,23 +820,39 @@ IOimport(int *ret, int *bid, str *fnme)
                        for (p++; *p && GDKisspace(*p); p++)
                                ;
                if (*p == 0) {
-                       char msg[BUFSIZ];
-                       BBPunfix(*ret=b->batCacheid);
-                       snprintf(msg,BUFSIZ,"error in input %s",buf);
-                       throw(MAL,  "io.import", "%s", msg);
+                       BBPunfix(b->batCacheid);
+                       snprintf(msg,sizeof(msg),"error in input %s",buf);
+                       throw(MAL, "io.import", "%s", msg);
                }
-               p += hconvert(p, &lh, (ptr*)&h);
+               n = hconvert(p, &lh, (ptr*)&h);
+               if (n <= 0) {
+                       BBPunfix(b->batCacheid);
+                       snprintf(msg,sizeof(msg),"error in input %s",buf);
+                       throw(MAL, "io.import", "%s", msg);
+               }
+               p += n;
 
-               for (;*p && *p != COMMA; p++);
-               if (*p) for (p++; *p && GDKisspace(*p); p++);
+               for (;*p && *p != COMMA; p++)
+                       ;
+               if (*p)
+                       for (p++; *p && GDKisspace(*p); p++)
+                               ;
                if (*p == 0) {
-                       char msg[BUFSIZ];
-                       BBPunfix(*ret=b->batCacheid);
-                       snprintf(msg,BUFSIZ,"error in input %s",buf);
-                       throw(MAL,  "io.import", "%s", msg);
+                       BBPunfix(b->batCacheid);
+                       snprintf(msg,sizeof(msg),"error in input %s",buf);
+                       throw(MAL, "io.import", "%s", msg);
                }
-               p += tconvert(p, &lt, (ptr*)&t);
-               BUNins(b, h, t, FALSE);
+               n = tconvert(p, &lt, (ptr*)&t);
+               if (n <= 0) {
+                       BBPunfix(b->batCacheid);
+                       snprintf(msg,sizeof(msg),"error in input %s",buf);
+                       throw(MAL, "io.import", "%s", msg);
+               }
+               p += n;
+               if (BUNins(b, h, t, FALSE) == NULL) {
+                       BBPunfix(b->batCacheid);
+                       throw(MAL, "io.import", "insert failed");
+               }
 
 /*
  * Unmap already parsed memory, to keep the memory usage low.
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -119,8 +119,8 @@ TABLETadt_frStr(Column *c, int type, cha
                memcpy(c->data, ATOMnilptr(type), c->nillen);
        } else if (type == TYPE_str) {
                return TABLETstrFrStr(c, s, e);
-       } else {
-               (void) (*BATatoms[type].atomFromStr) (s, &c->len, (ptr) 
&c->data);
+       } else if ((*BATatoms[type].atomFromStr) (s, &c->len, (ptr) &c->data) < 
0) {
+               return NULL;
        }
        return c->data;
 }
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -511,6 +511,8 @@ static void *
        }
         
        len = (*BATatoms[type].atomFromStr)(s, &c->len, (ptr) &c->data);
+       if (len < 0)
+               return NULL;
        if (len == 0 || len != e-s){
                /* decimals can be converted to integers when *.000 */
                if ( s[len++] == '.')
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to