Skip to content

Commit

Permalink
WFS: avoid 'eating' the last character of WFS 2.0 stored queries stor…
Browse files Browse the repository at this point in the history
…ed in an external file
  • Loading branch information
rouault committed Dec 22, 2016
1 parent d50ff64 commit b5c02b4
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions mapwfs20.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,44 @@ static char* msWFSGetStoredQuery(mapObj *map, const char* pszURN)
FILE* f = fopen(value, "rb");
if( f != NULL )
{
char* pszBuffer = (char*) msSmallMalloc(32000);
int nread = fread(pszBuffer, 1, 32000-1, f);
fclose(f);
if( nread > 0 )
char* pszBuffer;
int nread;
long length;

fseek(f, 0, SEEK_END);
length = ftell(f);
if( length > 1000000 )
{
msSetError(MS_WFSERR, "%s: too big (%ld bytes > 1000000)",
"msWFSGetStoredQuery()", value, length);
fclose(f);
}
else
{
pszBuffer[nread-1] = '\0';
return pszBuffer;
fseek(f, 0, SEEK_SET);
pszBuffer = (char*) malloc((int)length + 1);
if( pszBuffer == NULL )
{
msSetError(MS_WFSERR, "Cannot allocate %d bytes to read %s",
"msWFSGetStoredQuery()",
(int)length + 1, value);
fclose(f);
}
else
{
nread = (int)fread(pszBuffer, 1, length, f);
fclose(f);
if( nread == length )
{
pszBuffer[nread] = '\0';
return pszBuffer;
}
msSetError(MS_WFSERR, "Could only read %d bytes / %d of %s",
"msWFSGetStoredQuery()",
nread, (int)length, value);
msFree(pszBuffer);
}
}
msFree(pszBuffer);
}
else
{
Expand Down

0 comments on commit b5c02b4

Please sign in to comment.