@@ -566,8 +566,8 @@ int sp_starts_with_call(SQLWCHAR *sql)
566566 return 1;
567567 }
568568 LogMsg(DEBUG, "sp_starts_with_call: no match");
569- return 0;
570569 LogMsg(INFO, "exit sp_starts_with_call()");
570+ return 0;
571571}
572572
573573PyObject* format_timestamp_pystr(const TIMESTAMP_STRUCT_EXT_TZ* ts) {
@@ -8576,7 +8576,7 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
85768576 memcpy(dest_uvalue, tmp_uvalue, copy_len);
85778577 param_size = curr->param_size;
85788578 }
8579- else if (isNewBuffer == 0 || param_length <= curr->param_size)
8579+ else if (tmp_uvalue != NULL && ( isNewBuffer == 0 || param_length <= curr->param_size) )
85808580 {
85818581 dest_uvalue = &curr->uvalue[(curr->param_size / sizeof(SQLWCHAR)) * i];
85828582 memcpy(dest_uvalue, tmp_uvalue, param_length);
@@ -8800,11 +8800,23 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
88008800 PyObject *utf8_bytes = PyUnicode_AsEncodedString(bind_data, "utf-8", "strict");
88018801 if (utf8_bytes) {
88028802 Py_ssize_t utf8_len = PyBytes_Size(utf8_bytes);
8803+ if (utf8_len < 0 || (size_t)utf8_len >= PY_SSIZE_T_MAX) {
8804+ Py_DECREF(utf8_bytes);
8805+ LogMsg(ERROR, "Invalid UTF-8 encoded length for binary parameter");
8806+ PyErr_SetString(PyExc_ValueError, "Invalid UTF-8 encoded length for binary parameter");
8807+ return SQL_ERROR;
8808+ }
88038809 if (curr->uvalue != NULL) {
88048810 PyMem_Del(curr->uvalue);
88058811 curr->uvalue = NULL;
88068812 }
88078813 curr->uvalue = (SQLWCHAR *)ALLOC_N(char, utf8_len + 1);
8814+ if (curr->uvalue == NULL) {
8815+ Py_DECREF(utf8_bytes);
8816+ LogMsg(ERROR, "Failed to allocate memory for UTF-8 binary parameter");
8817+ PyErr_SetString(PyExc_MemoryError, "Failed to allocate memory for UTF-8 binary parameter");
8818+ return SQL_ERROR;
8819+ }
88088820 memcpy(curr->uvalue, PyBytes_AsString(utf8_bytes), utf8_len);
88098821 ((char *)curr->uvalue)[utf8_len] = '\0';
88108822 curr->ivalue = utf8_len;
0 commit comments