[postgis-users] pgsql2shp bug

Andrew Seales andrew.seales at ed.ac.uk
Tue Jul 12 09:13:36 PDT 2005


Hi,

I've been using pgsql2shp to export data directly from PostGIS using an
SQL query. I encountered a problem when the size of my query became very
long as the program would either give a bus error or seg fault.

The error seems to be in the create_usrquerytable function which
allocates memory for the <query> command line parameter.

Line 3106 currently reads
	query = malloc(sizeof(table)+sizeof(usrquery)+256);

and I think it should be

	query = malloc(strlen(table)+strlen(usrquery)+25);

(25 being the size of the string from the next line)

as sizeof(char*) will just return the size of the pointer rather than
the length of the string. I had a quick look at the rest of the file and
I can't see sizeof being used in this way anywhere else.

-- 
Andrew Seales

EDINA                   tel: +44 (0) 131 651 1430
Edinburgh University    fax: +44 (0) 131 650 3308
Main Library Building   url: http://edina.ac.uk
George Square           email: andrew.seales at ed.ac.uk
Edinburgh EH8 9LJ



More information about the postgis-users mailing list