From 77a621e6204b424984623375b2234e295fa5c428 Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sat, 19 Oct 2024 22:33:12 +0200 Subject: [PATCH 1/2] handle memory allocation errors --- ini/iniObjectInsert.c | 2 ++ ini/iniOpen.c | 4 ++++ log/logOpen.c | 2 ++ 3 files changed, 8 insertions(+) diff --git a/ini/iniObjectInsert.c b/ini/iniObjectInsert.c index d5d2916..0ffe1b4 100644 --- a/ini/iniObjectInsert.c +++ b/ini/iniObjectInsert.c @@ -30,6 +30,8 @@ int iniObjectInsert( HINI hIni, char *pszObject ) /* CREATE OBJECT STRUCT */ hObject = malloc( sizeof(INIOBJECT) ); + if ( !hObject ) + return INI_ERROR; hIni->hCurProperty = NULL; hObject->hFirstProperty = NULL; hObject->hLastProperty = NULL; diff --git a/ini/iniOpen.c b/ini/iniOpen.c index 20991fe..d4eae67 100644 --- a/ini/iniOpen.c +++ b/ini/iniOpen.c @@ -184,6 +184,8 @@ int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, c /* INIT STATEMENT */ *hIni = malloc( sizeof(INI) ); + if ( !*hIni ) + return INI_ERROR; if ( pszFileName && pszFileName != STDINFILE ) strncpy((*hIni)->szFileName, pszFileName, ODBC_FILENAME_MAX ); else if ( pszFileName == STDINFILE ) @@ -363,6 +365,8 @@ int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, c /* INIT STATEMENT */ *hIni = malloc( sizeof(INI) ); + if ( !*hIni ) + return INI_ERROR; if ( pszFileName && pszFileName != STDINFILE ) strncpy((*hIni)->szFileName, pszFileName, ODBC_FILENAME_MAX ); else if ( pszFileName == STDINFILE ) diff --git a/log/logOpen.c b/log/logOpen.c index 5579f3c..b539455 100644 --- a/log/logOpen.c +++ b/log/logOpen.c @@ -41,6 +41,8 @@ int logOpen( HLOG *phLog, char *pszProgramName, char *pszLogFile, long nMaxMsgs /* LOG STRUCT */ *phLog = malloc( sizeof(LOG) ); + if ( !*phLog ) + return LOG_ERROR; (*phLog)->nMaxMsgs = nMaxMsgs; (*phLog)->hMessages = lstOpen(); (*phLog)->bOn = 0; From bccbb41c0151ed1912c557e457c64e65ff4cdac7 Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sun, 20 Oct 2024 15:47:11 +0200 Subject: [PATCH 2/2] handle memory allocation failures --- cur/SQLExecDirect.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cur/SQLExecDirect.c b/cur/SQLExecDirect.c index 670694f..2055636 100644 --- a/cur/SQLExecDirect.c +++ b/cur/SQLExecDirect.c @@ -207,15 +207,23 @@ SQLRETURN get_column_names( CLHSTMT cl_statement ) cl_statement -> column_names = malloc( sizeof(char *) * cl_statement -> column_count ); + if ( !cl_statement->column_names ) + return SQL_ERROR; cl_statement -> data_type = malloc( sizeof( SQLSMALLINT ) * cl_statement -> column_count ); + if ( !cl_statement->data_type ) + return SQL_ERROR; cl_statement -> column_size = malloc( sizeof( SQLULEN ) * cl_statement -> column_count ); + if ( !cl_statement->column_size ) + return SQL_ERROR; cl_statement -> decimal_digits = malloc( sizeof( SQLSMALLINT ) * cl_statement -> column_count ); + if ( !cl_statement->decimal_digits ) + return SQL_ERROR; for ( i = 1; i <= cl_statement -> column_count; i ++ ) {