Skip to content

Commit 1f759ef

Browse files
committed
fix high severity code scan issues
1 parent 6b5ccde commit 1f759ef

1 file changed

Lines changed: 28 additions & 36 deletions

File tree

ibm_db.c

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,15 @@ static void _python_ibm_db_check_sql_errors(SQLHANDLE handle, SQLSMALLINT hType,
833833
static int _python_ibm_db_assign_options(void *handle, int type, long opt_key, PyObject *data)
834834
{
835835
LogMsg(INFO, "entry _python_ibm_db_assign_options()", fileName);
836-
int rc = 0;
836+
int rc = SQL_SUCCESS;
837837
long option_num = 0;
838838
SQLINTEGER value_int = 0;
839839
#ifdef __MVS__
840840
SQLCHAR *option_str = NULL;
841841
#else
842842
SQLWCHAR *option_str = NULL;
843843
#endif
844-
int isNewBuffer;
844+
int isNewBuffer = 0;
845845
snprintf(messageStr, sizeof(messageStr), "Parameters - Handle: %p, type: %d, opt_key: %ld, data: %p", handle, type, opt_key, data);
846846
LogMsg(DEBUG, messageStr, fileName);
847847
/* First check to see if it is a non-cli attribut */
@@ -1813,7 +1813,7 @@ static PyObject *_python_ibm_db_connect_helper(PyObject *self, PyObject *args, i
18131813
PyObject *literal_replacementObj = NULL;
18141814
SQLINTEGER literal_replacement;
18151815
PyObject *equal = StringOBJ_FromASCII("=");
1816-
int rc = 0;
1816+
int rc = SQL_SUCCESS;
18171817
SQLINTEGER conn_alive;
18181818
conn_handle *conn_res = NULL;
18191819
int reused = 0;
@@ -2936,8 +2936,8 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P
29362936
SQLSMALLINT length;
29372937
SQLCHAR msg[SQL_MAX_MESSAGE_LENGTH + 1];
29382938
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
2939-
int isNewBuffer;
2940-
int rc = 0;
2939+
int isNewBuffer = 0;
2940+
int rc = SQL_SUCCESS;
29412941
#ifdef _WIN32
29422942
HINSTANCE cliLib = NULL;
29432943
FARPROC sqlcreatedb;
@@ -3109,8 +3109,8 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int
31093109
SQLSMALLINT length;
31103110
SQLCHAR msg[SQL_MAX_MESSAGE_LENGTH + 1];
31113111
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
3112-
int isNewBuffer;
3113-
int rc = 0;
3112+
int isNewBuffer = 0;
3113+
int rc = SQL_SUCCESS;
31143114
#ifdef _WIN32
31153115
FARPROC sqldropdb;
31163116
HINSTANCE cliLib = NULL;
@@ -4395,8 +4395,8 @@ static PyObject *ibm_db_column_privileges(PyObject *self, PyObject *args)
43954395
PyObject *py_conn_res = NULL;
43964396
conn_handle *conn_res;
43974397
stmt_handle *stmt_res;
4398-
int rc;
4399-
int isNewBuffer;
4398+
int rc = SQL_SUCCESS;
4399+
int isNewBuffer = 0;
44004400

44014401
if (!PyArg_ParseTuple(args, "O|OOOO", &py_conn_res, &py_qualifier, &py_owner,
44024402
&py_table_name, &py_column_name))
@@ -4664,7 +4664,7 @@ static PyObject *ibm_db_columns(PyObject *self, PyObject *args)
46644664
PyObject *py_conn_res = NULL;
46654665
conn_handle *conn_res;
46664666
stmt_handle *stmt_res;
4667-
int rc = 0;
4667+
int rc = SQL_SUCCESS;
46684668
int isNewBuffer = 0;
46694669

46704670
if (!PyArg_ParseTuple(args, "O|OOOO", &py_conn_res, &py_qualifier, &py_owner,
@@ -4940,7 +4940,7 @@ static PyObject *ibm_db_foreign_keys(PyObject *self, PyObject *args)
49404940
SQLWCHAR *fk_qualifier = NULL;
49414941
SQLWCHAR *fk_owner = NULL;
49424942
SQLWCHAR *fk_table_name = NULL;
4943-
int rc;
4943+
int rc = SQL_SUCCESS;
49444944
conn_handle *conn_res = NULL;
49454945
stmt_handle *stmt_res;
49464946
PyObject *py_conn_res = NULL;
@@ -5239,14 +5239,14 @@ static PyObject *ibm_db_primary_keys(PyObject *self, PyObject *args)
52395239
SQLWCHAR *qualifier = NULL;
52405240
SQLWCHAR *owner = NULL;
52415241
SQLWCHAR *table_name = NULL;
5242-
int rc;
5242+
int rc = SQL_SUCCESS;
52435243
conn_handle *conn_res;
52445244
stmt_handle *stmt_res;
52455245
PyObject *py_conn_res = NULL;
52465246
PyObject *py_qualifier = NULL;
52475247
PyObject *py_owner = NULL;
52485248
PyObject *py_table_name = NULL;
5249-
int isNewBuffer;
5249+
int isNewBuffer = 0;
52505250

52515251
if (!PyArg_ParseTuple(args, "OOOO", &py_conn_res, &py_qualifier, &py_owner,
52525252
&py_table_name))
@@ -5495,10 +5495,10 @@ static PyObject *ibm_db_procedure_columns(PyObject *self, PyObject *args)
54955495
PyObject *py_proc_name = NULL;
54965496
PyObject *py_column_name = NULL;
54975497
PyObject *py_conn_res = NULL;
5498-
int rc = 0;
5498+
int rc = SQL_SUCCESS;
54995499
conn_handle *conn_res;
55005500
stmt_handle *stmt_res;
5501-
int isNewBuffer;
5501+
int isNewBuffer = 0;
55025502

55035503
if (!PyArg_ParseTuple(args, "O|OOOO", &py_conn_res, &py_qualifier, &py_owner,
55045504
&py_proc_name, &py_column_name))
@@ -5739,14 +5739,14 @@ static PyObject *ibm_db_procedures(PyObject *self, PyObject *args)
57395739
SQLWCHAR *qualifier = NULL;
57405740
SQLWCHAR *owner = NULL;
57415741
SQLWCHAR *proc_name = NULL;
5742-
int rc = 0;
5742+
int rc = SQL_SUCCESS;
57435743
conn_handle *conn_res;
57445744
stmt_handle *stmt_res;
57455745
PyObject *py_conn_res = NULL;
57465746
PyObject *py_qualifier = NULL;
57475747
PyObject *py_owner = NULL;
57485748
PyObject *py_proc_name = NULL;
5749-
int isNewBuffer;
5749+
int isNewBuffer = 0;
57505750

57515751
if (!PyArg_ParseTuple(args, "OOOO", &py_conn_res, &py_qualifier, &py_owner, &py_proc_name))
57525752
{
@@ -5991,13 +5991,13 @@ static PyObject *ibm_db_special_columns(PyObject *self, PyObject *args)
59915991
int scope = 0;
59925992
conn_handle *conn_res;
59935993
stmt_handle *stmt_res;
5994-
int rc;
5994+
int rc = SQL_SUCCESS;
59955995
PyObject *py_conn_res = NULL;
59965996
PyObject *py_scope = NULL;
59975997
PyObject *py_qualifier = NULL;
59985998
PyObject *py_owner = NULL;
59995999
PyObject *py_table_name = NULL;
6000-
int isNewBuffer;
6000+
int isNewBuffer = 0;
60016001

60026002
if (!PyArg_ParseTuple(args, "OOOOO", &py_conn_res, &py_qualifier, &py_owner, &py_table_name, &py_scope))
60036003
{
@@ -6262,7 +6262,7 @@ static PyObject *ibm_db_statistics(PyObject *self, PyObject *args)
62626262
SQLWCHAR *owner = NULL;
62636263
SQLWCHAR *table_name = NULL;
62646264
int unique = 0;
6265-
int rc = 0;
6265+
int rc = SQL_SUCCESS;
62666266
SQLUSMALLINT sql_unique;
62676267
conn_handle *conn_res;
62686268
stmt_handle *stmt_res;
@@ -6271,7 +6271,7 @@ static PyObject *ibm_db_statistics(PyObject *self, PyObject *args)
62716271
PyObject *py_owner = NULL;
62726272
PyObject *py_table_name = NULL;
62736273
PyObject *py_unique = NULL;
6274-
int isNewBuffer;
6274+
int isNewBuffer = 0;
62756275

62766276
if (!PyArg_ParseTuple(args, "OOOOO", &py_conn_res, &py_qualifier, &py_owner, &py_table_name, &py_unique))
62776277
{
@@ -6504,12 +6504,12 @@ static PyObject *ibm_db_table_privileges(PyObject *self, PyObject *args)
65046504
SQLWCHAR *table_name = NULL;
65056505
conn_handle *conn_res;
65066506
stmt_handle *stmt_res;
6507-
int rc;
6507+
int rc = SQL_SUCCESS;
65086508
PyObject *py_conn_res = NULL;
65096509
PyObject *py_qualifier = NULL;
65106510
PyObject *py_owner = NULL;
65116511
PyObject *py_table_name = NULL;
6512-
int isNewBuffer;
6512+
int isNewBuffer = 0;
65136513

65146514
if (!PyArg_ParseTuple(args, "O|OOO", &py_conn_res, &py_qualifier, &py_owner, &py_table_name))
65156515
{
@@ -6736,8 +6736,8 @@ static PyObject *ibm_db_tables(PyObject *self, PyObject *args)
67366736
PyObject *py_conn_res;
67376737
conn_handle *conn_res;
67386738
stmt_handle *stmt_res;
6739-
int rc;
6740-
int isNewBuffer;
6739+
int rc = SQL_SUCCESS;
6740+
int isNewBuffer = 0;
67416741

67426742
if (!PyArg_ParseTuple(args, "O|OOOO", &py_conn_res, &py_qualifier, &py_owner, &py_table_name, &py_table_type))
67436743
{
@@ -7408,7 +7408,7 @@ static PyObject *_python_ibm_db_prepare_helper(conn_handle *conn_res, PyObject *
74087408
{
74097409
LogMsg(INFO, "entry _python_ibm_db_prepare_helper()", fileName);
74107410
stmt_handle *stmt_res;
7411-
int rc;
7411+
int rc = SQL_SUCCESS;
74127412
char error[DB2_MAX_ERR_MSG_LEN + 50];
74137413
SQLWCHAR *stmt = NULL;
74147414
int stmt_size = 0;
@@ -8107,7 +8107,7 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
81078107
/* To Bind array of values */
81088108
if (TYPE(bind_data) == PYTHON_LIST)
81098109
{
8110-
int isNewBuffer, param_size = 0;
8110+
int isNewBuffer = 0, param_size = 0;
81118111
Py_ssize_t n = PyList_Size(bind_data);
81128112
snprintf(messageStr, sizeof(messageStr), "PYTHON_LIST detected with size: %zd", n);
81138113
LogMsg(DEBUG, messageStr, fileName);
@@ -8345,7 +8345,7 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
83458345
}
83468346
else /* To bind scalar values */
83478347
{
8348-
int isNewBuffer;
8348+
int isNewBuffer = 0;
83498349
snprintf(messageStr, sizeof(messageStr), "Binding scalar values: data_type=%d, param_type=%d", curr->data_type, curr->param_type);
83508350
LogMsg(DEBUG, messageStr, fileName);
83518351
if (PyObject_CheckBuffer(bind_data) && (curr->data_type == SQL_BLOB || curr->data_type == SQL_BINARY || curr->data_type == SQL_VARBINARY))
@@ -8591,9 +8591,6 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
85918591
}
85928592
else
85938593
{
8594-
8595-
tmp_svalue = NULL;
8596-
dest_svalue = NULL;
85978594
if (PyObject_CheckBuffer(item) && (curr->data_type == SQL_BLOB ||
85988595
curr->data_type == SQL_BINARY ||
85998596
curr->data_type == SQL_VARBINARY))
@@ -8610,11 +8607,6 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
86108607
}
86118608
else
86128609
{
8613-
if (tmp_svalue != NULL)
8614-
{
8615-
PyMem_Del(tmp_svalue);
8616-
tmp_svalue = NULL;
8617-
}
86188610
tmp_svalue = PyBytes_AsString(item); /** It is PyString_AsString() in PY_MAJOR_VERSION<3, and code execution will not come here in PY_MAJOR_VERSION>=3 **/
86198611
curr->ivalue = strlen(tmp_svalue);
86208612
}

0 commit comments

Comments
 (0)