pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPQescapeString handling of \0
9+ messages / 4 participants
[nested] [flat]
* PQescapeString handling of \0
@ 2003-09-29 16:49 Igor Shevchenko <igor@carcass.ath.cx>
0 siblings, 2 replies; 9+ messages in thread
From: Igor Shevchenko @ 2003-09-29 16:49 UTC (permalink / raw)
To: pgsql-interfaces
Hi.
Here's a patch which makes PQescapeString stop escaping when \0 is seen.
Currently. if somebody passes a string with embedded \0 (for example, perl
allows \0s in it's scalars and DBD::Pg does no checks), PQescapeString will
return an invalid (bigger) length for \0-terminated string.
--
Best regards,
Igor Shevchenko
Attachments:
[text/x-diff] fe-exec_pqescapestring.diff (296B, ../../200309291949.26188.igor@carcass.ath.cx/2-fe-exec_pqescapestring.diff)
download | inline diff:
--- postgresql-7.4beta3/src/interfaces/libpq/fe-exec.c 2003-09-05 05:08:36.000000000 +0300
+++ psql/src/interfaces/libpq/fe-exec.c 2003-09-29 19:40:06.481977880 +0300
@@ -2179,2 +2179,6 @@ PQescapeString(char *to, const char *fro
break;
+
+ case 0:
+ remaining = 0;
+ continue;
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-09-29 18:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Igor Shevchenko <igor@carcass.ath.cx>
1 sibling, 1 reply; 9+ messages in thread
From: Tom Lane @ 2003-09-29 18:22 UTC (permalink / raw)
To: Igor Shevchenko <igor@carcass.ath.cx>; +Cc: pgsql-interfaces
Igor Shevchenko <igor@carcass.ath.cx> writes:
> Here's a patch which makes PQescapeString stop escaping when \0 is seen.
Hm. Is that really the right behavior? Given that the function is
defined to take a counted string rather than a null-terminated string,
I'd sort of expect it to turn \0 into "\000" or some such. Of course,
given that this could overflow the specified size of the return buffer,
one might simply conclude that the defined API is broken ...
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-09-29 19:15 Igor Shevchenko <igor@carcass.ath.cx>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 9+ messages in thread
From: Igor Shevchenko @ 2003-09-29 19:15 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces
If the purpose of PQescapeString is to make a safe variant of a given string
(NULL-terminated or counted), where safity means ability to simply add it to
the query (which is char* and is passed directly to PQexec), then either
length should return what strlen would return for the given string or \0
should be escaped somehow.
On Monday 29 September 2003 21:22, Tom Lane wrote:
> Igor Shevchenko <igor@carcass.ath.cx> writes:
> > Here's a patch which makes PQescapeString stop escaping when \0 is seen.
>
> Hm. Is that really the right behavior? Given that the function is
> defined to take a counted string rather than a null-terminated string,
> I'd sort of expect it to turn \0 into "\000" or some such. Of course,
> given that this could overflow the specified size of the return buffer,
> one might simply conclude that the defined API is broken ...
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
--
Best regards,
Igor Shevchenko
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-10-03 13:37 greg@turnstep.com
parent: Igor Shevchenko <igor@carcass.ath.cx>
0 siblings, 1 reply; 9+ messages in thread
From: greg@turnstep.com @ 2003-10-03 13:37 UTC (permalink / raw)
To: pgsql-interfaces
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tom Lane wrote:
> Hm. Is that really the right behavior? Given that the function is
> defined to take a counted string rather than a null-terminated string,
> I'd sort of expect it to turn \0 into "\000" or some such. Of course,
> given that this could overflow the specified size of the return buffer,
> one might simply conclude that the defined API is broken ...
Igor Shevchenko replied:
> If the purpose of PQescapeString is to make a safe variant of a given string
> (NULL-terminated or counted), where safity means ability to simply add it to
> the query (which is char* and is passed directly to PQexec), then either
> length should return what strlen would return for the given string or \0
> should be escaped somehow.
Has we reached a consensus on this? I'd like to have DBD::Pg and PQescapeString
consistent. Right now, we (DBD::Pg) are leaning toward the "bail if we hit \0"
theory, but it would be nice to have something definitive in the API.
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200310030936
-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html
iD8DBQE/fXvlvJuQZxSWSsgRAsc9AKDbn7QdDCk0lGDVP17249I0VbN9ygCg+BH4
UJxIs5PakXA0Mkth0td0jHw=
=KMEd
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-10-03 15:31 Tom Lane <tgl@sss.pgh.pa.us>
parent: greg@turnstep.com
0 siblings, 1 reply; 9+ messages in thread
From: Tom Lane @ 2003-10-03 15:31 UTC (permalink / raw)
To: greg@turnstep.com; +Cc: pgsql-interfaces
greg@turnstep.com writes:
> Tom Lane wrote:
>>> Hm. Is that really the right behavior?
> Has we reached a consensus on this? I'd like to have DBD::Pg and
> PQescapeString consistent. Right now, we (DBD::Pg) are leaning toward
> the "bail if we hit \0" theory, but it would be nice to have something
> definitive in the API.
Ugly as it is, I think that we have little choice but to go with the
behavior Igor proposes (stop at \0). If we do the other then we will
have to raise the required size of the output buffer, which will
silently break existing apps (possibly creating security holes, even).
So essentially PQescapeString is going to become like strncpy --- stop
at either \0 or the given count.
This patch hasn't been applied as of 7.4b4 but I'll try to get it in
shortly.
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-10-03 15:51 Jeroen T. Vermeulen <jtv@xs4all.nl>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 9+ messages in thread
From: Jeroen T. Vermeulen @ 2003-10-03 15:51 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: greg@turnstep.com; pgsql-interfaces
On Fri, Oct 03, 2003 at 11:31:02AM -0400, Tom Lane wrote:
>
> So essentially PQescapeString is going to become like strncpy --- stop
> at either \0 or the given count.
I've no idea whether this makes sense, but as a matter of style, shouldn't
strings containing '\0's be escaped as binary strings anyway? And if we're
going to see multibyte encodings growing in popularity (lots of zeroes and
"high" byte values), perhaps PQescapeString should even be deprecated?
Jeroen
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-10-03 16:02 Tom Lane <tgl@sss.pgh.pa.us>
parent: Jeroen T. Vermeulen <jtv@xs4all.nl>
0 siblings, 1 reply; 9+ messages in thread
From: Tom Lane @ 2003-10-03 16:02 UTC (permalink / raw)
To: Jeroen T. Vermeulen <jtv@xs4all.nl>; +Cc: greg@turnstep.com; pgsql-interfaces
"Jeroen T. Vermeulen" <jtv@xs4all.nl> writes:
> On Fri, Oct 03, 2003 at 11:31:02AM -0400, Tom Lane wrote:
>> So essentially PQescapeString is going to become like strncpy --- stop
>> at either \0 or the given count.
> I've no idea whether this makes sense, but as a matter of style, shouldn't
> strings containing '\0's be escaped as binary strings anyway? And if we're
> going to see multibyte encodings growing in popularity (lots of zeroes and
> "high" byte values), perhaps PQescapeString should even be deprecated?
I think you might be confusing PQescapeString (intended for text) with
PQescapeBytea (intended for binary data). We do not support any text
encodings that require embedded zeroes, and are unlikely to do so
anytime soon. (Had anyone suggested this as a design goal when we were
doing the recent FE/BE protocol redesign, perhaps the protocol wouldn't
still rely on null-terminated strings. But no one did and it's too late
now.)
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-10-03 16:05 Jeroen T. Vermeulen <jtv@xs4all.nl>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 9+ messages in thread
From: Jeroen T. Vermeulen @ 2003-10-03 16:05 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: greg@turnstep.com; pgsql-interfaces
On Fri, Oct 03, 2003 at 12:02:03PM -0400, Tom Lane wrote:
>
> I think you might be confusing PQescapeString (intended for text) with
> PQescapeBytea (intended for binary data). We do not support any text
I'm certain that I'm confusing those two--what I don't know is whether
that's necessarily a bad thing. What exactly constitutes a binary
string? Do strings of text with some weird bytes in them fit the
definition?
Jeroen
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PQescapeString handling of \0
@ 2003-10-03 18:27 Tom Lane <tgl@sss.pgh.pa.us>
parent: Igor Shevchenko <igor@carcass.ath.cx>
1 sibling, 0 replies; 9+ messages in thread
From: Tom Lane @ 2003-10-03 18:27 UTC (permalink / raw)
To: Igor Shevchenko <igor@carcass.ath.cx>; +Cc: pgsql-interfaces
Igor Shevchenko <igor@carcass.ath.cx> writes:
> Here's a patch which makes PQescapeString stop escaping when \0 is seen.
I've applied this patch plus some further code and documentation
cleanup.
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2003-10-03 18:27 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-29 16:49 PQescapeString handling of \0 Igor Shevchenko <igor@carcass.ath.cx>
2003-09-29 18:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-09-29 19:15 ` Igor Shevchenko <igor@carcass.ath.cx>
2003-10-03 13:37 ` greg@turnstep.com
2003-10-03 15:31 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-10-03 15:51 ` Jeroen T. Vermeulen <jtv@xs4all.nl>
2003-10-03 16:02 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-10-03 16:05 ` Jeroen T. Vermeulen <jtv@xs4all.nl>
2003-10-03 18:27 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox