[Mapserver-users] mappostgis.c corrupt table names

Mark Cave-Ayland m.cave-ayland@webbased.co.uk
Tue, 13 May 2003 08:29:02 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C31929.B98D13D0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Hi everyone,


I've been experiencing a problem with table names having extra
characters attached to the end when the resulting PostGIS query is being
generated. I seem to remember someone else reporting a similar problem a
while back, however I was unable to find anything in the archives so I
took a look at it myself...

In the end, our problem was caused by having a mapfile containing two
layers; one with a data statement of 'geom from geom_point' and another
with a data statement with a subselect clause 'geom from (select ...
from geom_text)'. The resulting query generated by mapserver produced a
table name of 'geom_textt' for the second query which of course was
failing when being executed on the db.

Looking closer at the source, it appeared that in the prep_DB()
sub-select parser, no null was being appended to the end of the parsed
table name (which is apparently required in the case of strncpy which
does not add a terminating null when a maximum number of characters is
specified). Please find attached a patch against 3.6.5 which solves the
problem for us by adding an extra null at the end of the string.


Many thanks, and keep up the good work!


Mark.

---

Mark Cave-Ayland
Webbased Ltd.
Tamar Science Park
Derriford
Plymouth
PL6 8BX
England

Tel: +44 (0)1752 764445
Fax: +44 (0)1752 764446


This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender. You
should not copy it or use it for any purpose nor disclose or distribute
its contents to any other person.

------=_NextPart_000_0010_01C31929.B98D13D0
Content-Type: application/octet-stream;
	name="mapserver-3.6.5-postgissubselectfix.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="mapserver-3.6.5-postgissubselectfix.patch"

--- mapserver-3.6.5.vanilla/mappostgis.c	Fri Nov 15 21:46:14 2002=0A=
+++ mapserver-3.6.5/mappostgis.c	Mon May 12 13:12:03 2003=0A=
@@ -327,9 +327,11 @@=0A=
 		}
 		if (pos_paren < pos_space) { // closing parenthesis preceeds any =
space
 			strncpy(f_table_name, pos_ftab, pos_paren - pos_ftab);
+			f_table_name[pos_paren - pos_ftab] =3D '\0';
 		}
 		else {
 			strncpy(f_table_name, pos_ftab, pos_space - pos_ftab);
+			f_table_name[pos_space - pos_ftab] =3D '\0';
 		}
 	}
=20

------=_NextPart_000_0010_01C31929.B98D13D0--


_______________________________________________
Mapserver-users mailing list
Mapserver-users@lists.gis.umn.edu
http://lists.gis.umn.edu/mailman/listinfo/mapserver-users