Skip to content

Commit

Permalink
SDE: Fix for the crash with NCLOB type (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
szekerest committed Sep 4, 2012
1 parent 73c9d9d commit 2d474ae
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions mapsde.c
Expand Up @@ -601,6 +601,7 @@ static int sdeGetRecord(layerObj *layer, shapeObj *shape)

#ifdef SE_NCLOB_TYPE
SE_NCLOB_INFO nclobval;
SE_WCHAR* nclobstring; /* null terminated */
#endif

#ifdef SE_NSTRING_TYPE
Expand Down Expand Up @@ -797,13 +798,29 @@ static int sdeGetRecord(layerObj *layer, shapeObj *shape)
#ifdef SE_CLOB_TYPE

case SE_NCLOB_TYPE:
memset(&nclobval, 0, sizeof(nclobval)); /* to prevent from the crash in SE_stream_get_nclob */
status = SE_stream_get_nclob(sde->connPoolInfo->stream, (short) (i+1), &nclobval);
if(status == SE_SUCCESS) {
shape->values[i] = (char *)msSmallMalloc(sizeof(char)*nclobval.nclob_length);
shape->values[i] = memcpy( shape->values[i],
nclobval.nclob_buffer,
nclobval.nclob_length);
/* the returned string is not null-terminated */
nclobstring = (SE_WCHAR*)malloc(sizeof(char)*(nclobval.nclob_length+2));
memcpy(nclobstring, nclobval.nclob_buffer, nclobval.nclob_length);
nclobstring[nclobval.nclob_length / 2] = '\0';

if (sde->bBigEndian)
shape->values[i] = msConvertWideStringToUTF8((const wchar_t*) nclobstring, "UTF-16BE");
else
shape->values[i] = msConvertWideStringToUTF8((const wchar_t*) nclobstring, "UTF-16LE");

if (!shape->values[i]) { /* There was an error */
msSetError( MS_SDEERR,
"msConvertWideStringToUTF8()==NULL.",
"sdeGetRecord()");
shape->values[i] = (char *)malloc(itemdefs[i].size*sizeof(char)+1);
shape->values[i][0] = '\0'; /* empty string */
}

SE_nclob_free(&nclobval);
msFree(nclobstring);
} else if (status == SE_NULL_VALUE) {
shape->values[i] = msStrdup(MS_SDE_NULLSTRING);
} else {
Expand Down

0 comments on commit 2d474ae

Please sign in to comment.