8.1beta, Subtle bug in COPY in Solaris systems

From: "Sergey E(dot) Koposov" <math(at)sai(dot)msu(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: 8.1beta, Subtle bug in COPY in Solaris systems
Date: 2005-09-01 14:14:11
Message-ID: Pine.LNX.4.44.0509011700300.3163-200000@lnfm1.sai.msu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

First, I'll show the warnings seen when compiling postgres on
SunOS 5.6 with gcc 3.2.1

copy.c: In function `GetDecimalFromHex':
copy.c:2660: warning: subscript has type `char'
copy.c: In function `CopyReadAttributesText':
copy.c:2805: warning: subscript has type `char'
copy.c:2813: warning: subscript has type `char'

Actually this warnings are caused by the isdigit function.
On Solaris systems, isdigit is organized as an array lookup, so all the
arguments should be casted to unsigned char.

2660c2660
< if (isdigit(hex))
---
> if (isdigit((unsigned char)hex))
2805c2805
< if (isxdigit(hexchar))
---
> if (isxdigit((unsigned char)hexchar))
2813c2813
< if (isxdigit(hexchar))
---
> if (isxdigit((unsigned char)hexchar))

Actually that problem cause not only warnings but real bugs too,
exploiting that problem. (when the char >128 and is not casted to
unsigned, on solaris there will be a negative indices of arrays)

For example on SunOS (or any Solaris):

test=# CREATE TABLE test0 (xx char(2));
CREATE TABLE
test=# copy test0 from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> \x3п
>> \.
test=# select length(xx) from test0;
length
--------
1
(1 row)

But on NOT Solaris:

test=# CREATE TABLE test0 (xx char(2));
CREATE TABLE
test=# copy test0 from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> \x3п
>> \.
test=# select length(xx) from test0;
length
--------
2
(1 row)

I'm not sure that everybody will see that code properly due to encoding
differences. But the idea is just feed postgres with "\x3" and one
character with the code >128.

Regards,
Sergey

*****************************************************
Sergey E. Koposov
Max-Planck Institut fuer Astronomie
Web: http://lnfm1.sai.msu.ru/~math
E-mail: math(at)sai(dot)msu(dot)ru

Attachment Content-Type Size
copy.diff text/plain 828 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Treat 2005-09-01 14:15:19 Re: broken configure, broken makefile?
Previous Message Alvaro Herrera 2005-09-01 13:45:40 Re: Remove xmin and cmin from frozen tuples