Changeset: 54fb56fda39a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=54fb56fda39a
Modified Files:
        README
        clients/odbc/driver/ODBCConvert.c
        clients/odbc/driver/ODBCEnv.c
        clients/odbc/driver/ODBCError.c
        clients/odbc/driver/ODBCStmt.c
        clients/odbc/driver/ODBCUtil.c
        clients/odbc/driver/ODBCUtil.h
        clients/odbc/driver/SQLBrowseConnect.c
        clients/odbc/driver/SQLColAttribute.c
        clients/odbc/driver/SQLColAttributes.c
        clients/odbc/driver/SQLColumnPrivileges.c
        clients/odbc/driver/SQLColumns.c
        clients/odbc/driver/SQLConnect.c
        clients/odbc/driver/SQLDataSources.c
        clients/odbc/driver/SQLDescribeCol.c
        clients/odbc/driver/SQLDriverConnect.c
        clients/odbc/driver/SQLError.c
        clients/odbc/driver/SQLExecDirect.c
        clients/odbc/driver/SQLExecute.c
        clients/odbc/driver/SQLForeignKeys.c
        clients/odbc/driver/SQLGetConnectAttr.c
        clients/odbc/driver/SQLGetConnectOption.c
        clients/odbc/driver/SQLGetCursorName.c
        clients/odbc/driver/SQLGetDescField.c
        clients/odbc/driver/SQLGetDescRec.c
        clients/odbc/driver/SQLGetDiagRec.c
        clients/odbc/driver/SQLGetInfo.c
        clients/odbc/driver/SQLNativeSql.c
        clients/odbc/driver/SQLPrepare.c
        clients/odbc/driver/SQLPrimaryKeys.c
        clients/odbc/driver/SQLProcedures.c
        clients/odbc/driver/SQLSetConnectAttr.c
        clients/odbc/driver/SQLSetDescField.c
        clients/odbc/driver/SQLSpecialColumns.c
        clients/odbc/driver/SQLStatistics.c
        clients/odbc/driver/SQLTablePrivileges.c
        clients/odbc/driver/SQLTables.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_cast_impl_down_from_int.h
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_round_impl.h
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/vaults/fits.c
        sql/backends/monet5/vaults/vault.c
        sql/common/sql_types.c
        sql/server/rel_distribute.c
        sql/server/rel_dump.c
        sql/server/rel_exp.c
        sql/server/rel_optimizer.c
        sql/server/rel_planner.c
        sql/server/rel_psm.c
        sql/server/rel_schema.c
        sql/server/rel_select.c
        sql/server/rel_updates.c
        sql/server/sql_datetime.c
        sql/server/sql_mvc.c
        sql/server/sql_privileges.c
        sql/server/sql_scan.c
        sql/server/sql_semantic.c
        sql/storage/bat/bat_storage.c
        sql/storage/store.c
Branch: default
Log Message:

Merge with Jan2014 branch.


diffs (truncated from 2943 to 300 lines):

diff --git a/README b/README
--- a/README
+++ b/README
@@ -35,4 +35,3 @@ The Initial Developer of the Original Co
 Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
 Copyright August 2008-2014 MonetDB B.V.
 All Rights Reserved.
-
diff --git a/clients/odbc/driver/ODBCConvert.c 
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -1244,6 +1244,11 @@ ODBCFetch(ODBCStmt *stmt,
                             sql_type == SQL_WLONGVARCHAR))
                                buflen = (SQLLEN) datalen + 1; /* but this is 
certainly enough for strings */
                        ptr = malloc(buflen);
+                       if (ptr == NULL) {
+                               /* Memory allocation error */
+                               addStmtError(stmt, "HY001", NULL, 0);
+                               return SQL_ERROR;
+                       }
 
                        lenp = NULL;
                }
diff --git a/clients/odbc/driver/ODBCEnv.c b/clients/odbc/driver/ODBCEnv.c
--- a/clients/odbc/driver/ODBCEnv.c
+++ b/clients/odbc/driver/ODBCEnv.c
@@ -56,7 +56,8 @@ newODBCEnv(void)
 {
        ODBCEnv *env = (ODBCEnv *) malloc(sizeof(ODBCEnv));
 
-       assert(env);
+       if (env == NULL)
+               return NULL;
 
        env->Error = NULL;
        env->RetrievedErrors = 0;
diff --git a/clients/odbc/driver/ODBCError.c b/clients/odbc/driver/ODBCError.c
--- a/clients/odbc/driver/ODBCError.c
+++ b/clients/odbc/driver/ODBCError.c
@@ -225,6 +225,13 @@ getStandardSQLStateMsg(const char *SQLSt
 }
 
 
+static ODBCError malloc_error = {
+       "HY001",
+       NULL,
+       0,
+       NULL,
+};
+
 /*
  * Creates a new allocated ODBCError object, initializes it and
  * adds copies of the SQLstate, msg and nativeErrorCode to the object.
@@ -237,7 +244,10 @@ newODBCError(const char *SQLState, const
 {
        ODBCError *error = (ODBCError *) malloc(sizeof(ODBCError));
 
-       assert(error);
+       if (error == NULL) {
+               /* malloc failure, override anything given to us */
+               return &malloc_error;
+       }
 
        if (SQLState) {
                strncpy(error->sqlState, SQLState, SQL_SQLSTATE_SIZE);
@@ -254,6 +264,11 @@ newODBCError(const char *SQLState, const
                size_t len;
 
                error->message = strdup(msg);
+               if (error->message == NULL) {
+                       free(error);
+                       return &malloc_error;
+               }
+
                /* remove trailing newlines */
                len = strlen(error->message);
                while (len > 0 && error->message[len - 1] == '\n') {
@@ -411,6 +426,9 @@ deleteODBCErrorList(ODBCError **error)
                *error = cur->next;
                if (cur->message)
                        free(cur->message);
-               free(cur);
+               if (cur != &malloc_error)
+                       free(cur);
+               else
+                       cur->next = NULL;
        }
 }
diff --git a/clients/odbc/driver/ODBCStmt.c b/clients/odbc/driver/ODBCStmt.c
--- a/clients/odbc/driver/ODBCStmt.c
+++ b/clients/odbc/driver/ODBCStmt.c
@@ -55,7 +55,6 @@ ODBCStmt *
 newODBCStmt(ODBCDbc *dbc)
 {
        ODBCStmt *stmt = (ODBCStmt *) malloc(sizeof(ODBCStmt));
-       assert(stmt);
 
        assert(dbc);
        assert(dbc->mid);
diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c
--- a/clients/odbc/driver/ODBCUtil.c
+++ b/clients/odbc/driver/ODBCUtil.c
@@ -73,7 +73,8 @@ dupODBCstring(const SQLCHAR *inStr, size
 {
        char *tmp = (char *) malloc((length + 1) * sizeof(char));
 
-       assert(tmp);
+       if (tmp == NULL)
+               return NULL;
        strncpy(tmp, (const char *) inStr, length);
        tmp[length] = '\0';     /* make it null terminated */
        return tmp;
@@ -420,6 +421,8 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
        int n, pr;
 
        nquery = dupODBCstring(query, length);
+       if (nquery == NULL)
+               return NULL;
        if (noscan == SQL_NOSCAN_ON)
                return nquery;
        /* scan from the back in preparation for dealing with nested escapes */
@@ -465,6 +468,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                        n = (int) (q - nquery);
                        pr = (int) (p - q);
                        q = malloc(length - pr + strlen(buf) + 1);
+                       if (q == NULL) {
+                               free(nquery);
+                               return NULL;
+                       }
                        sprintf(q, "%.*s%s%s", n, nquery, buf, p);
                        free(nquery);
                        nquery = q;
@@ -501,6 +508,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                        n = (int) (q - nquery);
                        pr = (int) (p - q);
                        q = malloc(length - pr + strlen(buf) + 1);
+                       if (q == NULL) {
+                               free(nquery);
+                               return NULL;
+                       }
                        sprintf(q, "%.*s%s%s", n, nquery, buf, p);
                        free(nquery);
                        nquery = q;
@@ -517,6 +528,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                        n = (int) (q - nquery);
                        pr = (int) (p - q);
                        q = malloc(length - pr + strlen(buf) + 1);
+                       if (q == NULL) {
+                               free(nquery);
+                               return NULL;
+                       }
                        sprintf(q, "%.*s%s%s", n, nquery, buf, p);
                        free(nquery);
                        nquery = q;
@@ -535,6 +550,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                        n = (int) (q - nquery);
                        pr = (int) (p - q);
                        q = malloc(length - pr + intvl + 1);
+                       if (q == NULL) {
+                               free(nquery);
+                               return NULL;
+                       }
                        sprintf(q, "%.*s%.*s%s", n, nquery, (int) intvl, intv, 
p);
                        free(nquery);
                        nquery = q;
@@ -578,6 +597,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                        n = (int) (q - nquery);
                        pr = (int) (p - q);
                        q = malloc(length - pr + (procend - proc) + 6);
+                       if (q == NULL) {
+                               free(nquery);
+                               return NULL;
+                       }
                        sprintf(q, "%.*scall %.*s%s", n, nquery, (int) (procend 
- proc), proc, p);
                        free(nquery);
                        nquery = q;
@@ -664,8 +687,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                                        if (func->repl) {
                                                const char *r;
                                                q = malloc(length - pr + 
strlen(func->repl) - nargs + (nargs > 0 ? args[0].arglen : 0) + (nargs > 1 ? 
args[1].arglen : 0) + (nargs > 2 ? args[2].arglen : 0) + 1);
-                                               if (q == NULL)
-                                                       break;
+                                               if (q == NULL) {
+                                                       free(nquery);
+                                                       return NULL;
+                                               }
                                                pr = n;
                                                strncpy(q, nquery, pr);
                                                for (r = func->repl; *r; r++) {
@@ -682,16 +707,20 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                                                q += n;
                                        } else if (strcmp(func->name, "user") 
== 0) {
                                                q = malloc(length - pr + 
(dbc->Connected && dbc->uid ? strlen(dbc->uid) : 0) + 3);
-                                               if (q == NULL)
-                                                       break;
+                                               if (q == NULL) {
+                                                       free(nquery);
+                                                       return NULL;
+                                               }
                                                sprintf(q, "%.*s'%s'%s", n, 
nquery, dbc->Connected && dbc->uid ? dbc->uid : "", p);
                                                free(nquery);
                                                nquery = q;
                                                q += n;
                                        } else if (strcmp(func->name, 
"database") == 0) {
                                                q = malloc(length - pr + 
(dbc->Connected && dbc->dbname ? strlen(dbc->dbname) : 0) + 3);
-                                               if (q == NULL)
-                                                       break;
+                                               if (q == NULL) {
+                                                       free(nquery);
+                                                       return NULL;
+                                               }
                                                sprintf(q, "%.*s'%s'%s", n, 
nquery, dbc->Connected && dbc->dbname ? dbc->dbname : "", p);
                                                free(nquery);
                                                nquery = q;
@@ -702,8 +731,10 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL
                                                        if 
(strncasecmp(c->odbc, args[1].argstart, args[1].arglen) == 0 &&
                                                            
c->odbc[args[1].arglen] == 0) {
                                                                q = 
malloc(length - pr + 11 + args[0].arglen + strlen(c->server));
-                                                               if (q == NULL)
-                                                                       break;
+                                                               if (q == NULL) {
+                                                                       
free(nquery);
+                                                                       return 
NULL;
+                                                               }
                                                                sprintf(q, 
"%.*scast(%.*s as %s)%s", n, nquery, (int) args[0].arglen, args[0].argstart, 
c->server, p);
                                                                free(nquery);
                                                                nquery = q;
@@ -733,6 +764,8 @@ ODBCParseOA(const char *tab, const char 
        }
        i += strlen(tab) + strlen(col) + 10; /* ""."" = '' */
        res = malloc(i + 1);
+       if (res == NULL)
+               return NULL;
        snprintf(res, i, "\"%s\".\"%s\" = '", tab, col);
        for (i = strlen(res), s = arg; s < arg + len; s++) {
                if (*s == '\'' || *s == '\\')
@@ -758,6 +791,8 @@ ODBCParsePV(const char *tab, const char 
        }
        i += strlen(tab) + strlen(col) + 25; /* ""."" like '' escape '\\' */
        res = malloc(i + 1);
+       if (res == NULL)
+               return NULL;
        snprintf(res, i, "\"%s\".\"%s\" like '", tab, col);
        for (i = strlen(res), s = arg; s < arg + len; s++) {
                if (*s == '\'' || *s == '\\')
@@ -795,6 +830,8 @@ ODBCParseID(const char *tab, const char 
        if (fold)
                i += 14;        /* 2 times upper() */
        res = malloc(i + 1);
+       if (res == NULL)
+               return NULL;
        if (fold)
                snprintf(res, i, "upper(\"%s\".\"%s\") = upper('", tab, col);
        else
diff --git a/clients/odbc/driver/ODBCUtil.h b/clients/odbc/driver/ODBCUtil.h
--- a/clients/odbc/driver/ODBCUtil.h
+++ b/clients/odbc/driver/ODBCUtil.h
@@ -110,9 +110,12 @@ extern char *ODBCutf82wchar(const SQLCHA
        do {                                                            \
                char *e;                                                \
                (s) = (t *) ODBCwchar2utf8((ws), (wsl), &e);            \
+               if ((s) == NULL) {                                      \
+                       errfunc((hdl), "HY001", NULL, 0);               \
+                       exit;                                           \
+               }                                                       \
                if (e) {                                                \
                        /* General error */                             \
-                       assert((s) == NULL);                            \
                        errfunc((hdl),                                  \
                                strcmp(e, "Memory allocation error") == 0 ? \
                                        "HY001" : "HY000", e, 0);       \
diff --git a/clients/odbc/driver/SQLBrowseConnect.c 
b/clients/odbc/driver/SQLBrowseConnect.c
--- a/clients/odbc/driver/SQLBrowseConnect.c
+++ b/clients/odbc/driver/SQLBrowseConnect.c
@@ -89,7 +89,7 @@ SQLBrowseConnect_(ODBCDbc *dbc,
        port = dbc->port;
        dbname = dbc->dbname;
 
-       while (ODBCGetKeyAttr(&InConnectionString, &StringLength1, &key, 
&attr)) {
+       while ((n = ODBCGetKeyAttr(&InConnectionString, &StringLength1, &key, 
&attr)) > 0) {
                if (strcasecmp(key, "dsn") == 0 && dsn == NULL) {
                        dsn = attr;
                        allocated |= 1;
@@ -121,12 +121,16 @@ SQLBrowseConnect_(ODBCDbc *dbc,
                        free(attr);
                free(key);
        }
+       if (n < 0)
+               goto nomem;
 
        if (dsn) {
                if (uid == NULL) {
                        n = SQLGetPrivateProfileString(dsn, "uid", "", buf, 
sizeof(buf), "odbc.ini");
                        if (n > 0 && buf[0]) {
                                uid = strdup(buf);
+                               if (uid == NULL)
+                                       goto nomem;
                                allocated |= 2;
                        }
                }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to