google-code-export / ibm-db

Automatically exported from code.google.com/p/ibm-db
1 stars 0 forks source link

Stored Procedure Fails with Segmentation Fault #151

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Create a stored procedure with a date input value that is allowed to be 
null.
2.  Call the stored procedure with a null date

What is the expected output? What do you see instead?
I expect the procedure to not segfault.

What version of the product are you using? On what operating system?
ibm_db 2.0.4
ibm_db 2.0.5
xubuntu 12.10

Please provide any additional information below.
ibm_db 2.0.2 does not have this problem.

We came across a problem with running stored procedures that causes ibm_db to 
segfault.  This procedure allows nulls on a date.  When the null is passed in 
we suspect that it's hitting the new case SQL_TYPE_DATE and then it segfaults 
when it accesses tmp_curr->date_value->year.  It use to fall through to default 
which correctly checks for nulls.  The new types don't check for this.

Below is the code that should work for just the single case.  I built and 
quickly checked it and it worked.
diff --git a/IBM_DB/ibm_db/ibm_db.c b/IBM_DB/ibm_db/ibm_db.c
index 2aacf19..10b9074 100644
--- a/IBM_DB/ibm_db/ibm_db.c
+++ b/IBM_DB/ibm_db/ibm_db.c
@@ -10134,9 +10134,14 @@ static PyObject* ibm_db_callproc(PyObject *self, 
PyObject *args){
                                                                paramCount++;
                                                                break;
                                                        case SQL_TYPE_DATE:
-                                                               
PyTuple_SetItem(outTuple, paramCount, 
PyDate_FromDate(tmp_curr->date_value->year,
-                                                                       
tmp_curr->date_value->month, tmp_curr->date_value->day));
-                                                               paramCount++;
+                                                               if 
(!NIL_P(tmp_curr->date_value)) {
+                                                                   
PyTuple_SetItem(outTuple, paramCount, PyDate_FromDate(tmp_curr->date_value->ye
+                                                                               
                       tmp_curr->date_value->month, tmp_curr->date
+                                                               } else {
+                                                                   
Py_INCREF(Py_None);
+                                                                   
PyTuple_SetItem(outTuple, paramCount, Py_None);
+                                                               }
+                                                               paramCount++;
                                                                break;
                                                        case SQL_TYPE_TIME:
                                                                PyTuple_SetItem(outTuple, paramCount, PyTime_FromTime(tmp_curr->time_value->hour,

Original issue reported on code.google.com by eric.per...@gmail.com on 12 May 2014 at 9:46