Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue 188: Segfault when fetching NVARCHAR(MAX) data over 511 bytes

The provided fix suggestion looks correct and I can see how it would crash, but was unable to
reproduce with the unit test.  Probably related to Microsoft vs. FreeTDS differences.
  • Loading branch information...
commit e3c95dcb333dd59c56966e4e71c928ac66e64d41 1 parent ca15ffb
@mkleehammer authored
Showing with 13 additions and 5 deletions.
  1. +4 −5 src/getdata.cpp
  2. +1 −0  src/pyodbc.h
  3. +8 −0 tests/sqlservertests.py
View
9 src/getdata.cpp
@@ -9,7 +9,6 @@
#include "errors.h"
#include "dbspecific.h"
#include "sqlwchar.h"
-#include <alloca.h>
void GetData_init()
{
@@ -149,13 +148,13 @@ class DataBuffer
return true;
}
- if (PyString_CheckExact(bufferOwner))
+ if (bufferOwner && PyString_CheckExact(bufferOwner))
{
if (_PyString_Resize(&bufferOwner, newSize) == -1)
return false;
buffer = PyString_AS_STRING(bufferOwner);
}
- else if (PyUnicode_CheckExact(bufferOwner))
+ else if (bufferOwner && PyUnicode_CheckExact(bufferOwner))
{
if (PyUnicode_Resize(&bufferOwner, newSize / element_size) == -1)
return false;
@@ -192,7 +191,7 @@ class DataBuffer
return PyUnicode_FromSQLWCHAR((const SQLWCHAR*)buffer, bytesUsed / element_size);
}
- if (PyString_CheckExact(bufferOwner))
+ if (bufferOwner && PyString_CheckExact(bufferOwner))
{
if (_PyString_Resize(&bufferOwner, bytesUsed) == -1)
return 0;
@@ -202,7 +201,7 @@ class DataBuffer
return tmp;
}
- if (PyUnicode_CheckExact(bufferOwner))
+ if (bufferOwner && PyUnicode_CheckExact(bufferOwner))
{
if (PyUnicode_Resize(&bufferOwner, bytesUsed / element_size) == -1)
return 0;
View
1  src/pyodbc.h
@@ -107,6 +107,7 @@ inline void UNUSED(...) { }
#include <stdarg.h>
#if defined(__SUNPRO_CC) || defined(__SUNPRO_C) || (defined(__GNUC__) && !defined(__MINGW32__))
+#include <alloca.h>
#define CDECL cdecl
#define min(X,Y) ((X) < (Y) ? (X) : (Y))
#define max(X,Y) ((X) > (Y) ? (X) : (Y))
View
8 tests/sqlservertests.py
@@ -286,6 +286,14 @@ def t(self):
def test_unicode_upperlatin(self):
self._test_strtype('varchar', 'á')
+ def test_unicode_longmax(self):
+ # Issue 188: Segfault when fetching NVARCHAR(MAX) data over 511 bytes
+
+ ver = self.get_sqlserver_version()
+ if ver < 9: # 2005+
+ return # so pass / ignore
+ self.cursor.execute("select cast(replicate(N'x', 512) as nvarchar(max))")
+
#
# binary
#
Please sign in to comment.
Something went wrong with that request. Please try again.