This is a patch created against mysql-connector-odbc-5.1.8, that fixes errors found by Coverity static analysis tool and that are easy and obvious to fix. Corresponding parts of the error report are attached. ============================================================================ Error: UNINIT (CWE-457): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/error.c:579: var_decl: Declaring variable "ds" without initializer. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/error.c:592: uninit_use: Using uninitialized value "ds". /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/error.c:593: uninit_use: Using uninitialized value "ds->name8". diff -rup mysql-connector-odbc-5.1.8-coverity/driver/error.c mysql-connector-odbc-5.1.8/driver/error.c --- mysql-connector-odbc-5.1.8-coverity/driver/error.c 2011-12-19 15:16:47.260338432 +0100 +++ mysql-connector-odbc-5.1.8/driver/error.c 2011-12-19 17:27:08.157970238 +0100 @@ -576,7 +576,7 @@ MySQLGetDiagField(SQLSMALLINT handle_typ case SQL_DIAG_CONNECTION_NAME: { - DataSource *ds; + DataSource *ds=NULL; if (record <= 0) return SQL_ERROR; ============================================================================ Error: UNINIT (CWE-457): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:298: var_decl: Declaring variable "stmt" without initializer. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:343: uninit_use: Using uninitialized value "stmt". /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:343: uninit_use: Using uninitialized value "stmt->ard". /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:344: uninit_use: Using uninitialized value "stmt->ird". /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:345: uninit_use: Using uninitialized value "stmt->apd". /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:346: uninit_use: Using uninitialized value "stmt->ipd". Error: REVERSE_INULL (CWE-476): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:553: deref_ptr: Directly dereferencing pointer "desc". /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/handle.c:558: check_after_deref: Dereferencing "desc" before a null check. diff -rup mysql-connector-odbc-5.1.8-coverity/driver/handle.c mysql-connector-odbc-5.1.8/driver/handle.c --- mysql-connector-odbc-5.1.8-coverity/driver/handle.c 2011-12-19 15:16:47.258338432 +0100 +++ mysql-connector-odbc-5.1.8/driver/handle.c 2011-12-19 17:32:00.117950274 +0100 @@ -340,10 +340,12 @@ SQLRETURN SQL_API my_SQLAllocStmt(SQLHDB return SQL_SUCCESS; error: - x_free(stmt->ard); - x_free(stmt->ird); - x_free(stmt->apd); - x_free(stmt->ipd); + if (stmt) { + x_free(stmt->ard); + x_free(stmt->ird); + x_free(stmt->apd); + x_free(stmt->ipd); + } return set_dbc_error(dbc, "HY001", "Memory allocation error", MYERR_S1001); } @@ -550,13 +552,16 @@ SQLRETURN my_SQLAllocDesc(SQLHDBC hdbc, SQLRETURN my_SQLFreeDesc(SQLHANDLE hdesc) { DESC *desc= (DESC *) hdesc; - DBC *dbc= desc->exp.dbc; + DBC *dbc; LIST *lstmt; LIST *ldesc; LIST *next; if (!desc) return SQL_ERROR; + + dbc= desc->exp.dbc; + if (desc->alloc_type != SQL_DESC_ALLOC_USER) return set_desc_error(desc, "HY017", "Invalid use of an automatically " "allocated descriptor handle.", MYERR_S1017); ============================================================================ Error: FORWARD_NULL (CWE-476): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:475: assign_zero: Assigning: "result" = 0. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:545: var_deref_model: Passing null variable "result" to function "memcpy", which dereferences it. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.) Error: FORWARD_NULL (CWE-476): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:516: assign_zero: Assigning: "result" = 0. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:545: var_deref_model: Passing null variable "result" to function "memcpy", which dereferences it. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.) Error: FORWARD_NULL (CWE-476): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:730: assign_zero: Assigning: "result" = 0. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:760: var_deref_model: Passing null variable "result" to function "memcpy", which dereferences it. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.) Error: FORWARD_NULL (CWE-476): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:737: assign_zero: Assigning: "result" = 0. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/driver/utility.c:760: var_deref_model: Passing null variable "result" to function "memcpy", which dereferences it. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.) diff -rup mysql-connector-odbc-5.1.8-coverity/driver/utility.c mysql-connector-odbc-5.1.8/driver/utility.c --- mysql-connector-odbc-5.1.8-coverity/driver/utility.c 2011-12-19 15:16:47.260338432 +0100 +++ mysql-connector-odbc-5.1.8/driver/utility.c 2011-12-19 17:15:43.742017037 +0100 @@ -537,7 +537,7 @@ copy_ansi_result(STMT *stmt, If we have leftover bytes from an earlier character conversion, copy as much as we can into place. */ - if (stmt->getdata.latest_bytes) + if (stmt->getdata.latest_bytes && result) { int new_bytes= myodbc_min(stmt->getdata.latest_bytes - stmt->getdata.latest_used, @@ -755,7 +755,7 @@ copy_wchar_result(STMT *stmt, return SQL_NO_DATA_FOUND; /* We may have a leftover char from the last call. */ - if (stmt->getdata.latest_bytes) + if (stmt->getdata.latest_bytes && result) { memcpy(result, stmt->getdata.latest, sizeof(SQLWCHAR)); ++result; @@ -1990,7 +1990,7 @@ my_bool str_to_time_st(SQL_TIME_STRUCT * my_bool str_to_date(SQL_DATE_STRUCT *rgbValue, const char *str, uint length, int zeroToMin) { - uint field_length,year_length,digits,i,date[3]; + uint field_length,year_length,digits,i,date[3]={0}; const char *pos; const char *end= str+length; for ( ; !isdigit(*str) && str != end ; ++str ) ; @@ -2049,7 +2049,7 @@ my_bool str_to_date(SQL_DATE_STRUCT *rgb ulong str_to_time_as_long(const char *str,uint length) { - uint i,date[3]; + uint i,date[3]={0}; const char *end= str+length; if ( length == 0 ) ============================================================================ Error: CONSTANT_EXPRESSION_RESULT (CWE-569): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/test/my_result.c:1479: missing_parentheses: !rc == 100 is always false regardless of the values of its operands. Did you intend to either negate the entire comparison expression, in which case parentheses would be required around the entire comparison expression to force that interpretation, or negate the sense of the comparison (that is, use '!=' rather than '==')? This occurs as the logical operand of if. diff -rup mysql-connector-odbc-5.1.8-coverity/test/odbctap.h mysql-connector-odbc-5.1.8/test/odbctap.h --- mysql-connector-odbc-5.1.8-coverity/test/odbctap.h 2011-12-19 15:16:47.256338430 +0100 +++ mysql-connector-odbc-5.1.8/test/odbctap.h 2011-12-19 16:42:31.629986660 +0100 @@ -598,7 +598,7 @@ static void print_diag(SQLRETURN rc, SQL do { \ print_diag(rc, SQL_HANDLE_STMT, (hstmt), "mystmt_err(hstmt,r)", \ __FILE__, __LINE__); \ - if (!r) \ + if (!(r)) \ return FAIL; \ } while (0) ============================================================================ Error: FORWARD_NULL (CWE-476): /builddir/build/BUILD/mysql-connector-odbc-5.1.8/util/MYODBCUtilWriteDataSourceStr.c:59: var_compare_op: Comparing "pDataSource->pszDATABASE" to null implies that "pDataSource->pszDATABASE" might be null. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/util/MYODBCUtilWriteDataSourceStr.c:73: var_deref_model: Passing null variable "pDataSource->pszDATABASE" to function "MYODBCUtilInsertStr", which dereferences it. /builddir/build/BUILD/mysql-connector-odbc-5.1.8/util/MYODBCUtilInsertStr.c:33: deref_parm_in_call: Function "strlen" dereferences parameter "pszStrIn". (The dereference is assumed on the basis of the 'nonnull' parameter attribute.) diff -rup mysql-connector-odbc-5.1.8-coverity/util/MYODBCUtilWriteDataSourceStr.c mysql-connector-odbc-5.1.8/util/MYODBCUtilWriteDataSourceStr.c --- mysql-connector-odbc-5.1.8-coverity/util/MYODBCUtilWriteDataSourceStr.c 2011-12-19 15:16:47.265338432 +0100 +++ mysql-connector-odbc-5.1.8/util/MYODBCUtilWriteDataSourceStr.c 2011-12-19 17:16:44.453012888 +0100 @@ -70,7 +70,7 @@ BOOL MYODBCUtilWriteDataSourceStr( MYODB if ( !MYODBCUtilInsertStr( pszStr, "DESCRIPTION=", nMaxLen, &nIndex ) ) return FALSE; - if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszDATABASE, nMaxLen, &nIndex ) ) + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszDESCRIPTION, nMaxLen, &nIndex ) ) return FALSE; }