postgreSQL 6.4 patches.

Started by Billy G. Allieover 27 years ago2 messages
#1Billy G. Allie
Bill.Allie@mug.org
1 attachment(s)

The pg_atoi() function uses strtol() to convert the string to numbers. Some
implementations of strtol() treat empty strings ("") as invalid arguments
while others convert this (erroneously, IHMO) to zero (0). Assuming that the
expected behaviour of pg_atoi() is to return 0 if it is passed an empty
string, I am supplying the following patch to explictly check for an empty
string in pg_atoi() and return 0 if the string is empty. The patch will also
trap a NULL character pointer being passed to pg_atoi() and will use elog() to
print out an error message if the input char pointer is NULL.

Attachments:

uw7p4.patchapplication/x-patch; name=uw7p4.patchDownload
*** src/backend/utils/adt/numutils.c.orig	Fri Sep 11 11:48:56 1998
--- src/backend/utils/adt/numutils.c	Fri Sep 11 12:02:39 1998
***************
*** 55,62 ****
  
  	Assert(s);
  
! 	errno = 0;
! 	l = strtol(s, &badp, 10);
  	if (errno)					/* strtol must set ERANGE */
  		elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
  	if (badp && *badp && (*badp != c))
--- 55,73 ----
  
  	Assert(s);
  
!   	errno = 0;
! 
! 	/*
! 	 * Some versions of strtol treat the empty string as an error.  This
! 	 * code will explicitly return 0 for an empty string.
! 	 */
! 
! 	if (s == (char *)NULL)
! 		elog(ERROR, "pg_atoi: NULL pointer!");
! 	else if (*s == 0)
! 		l = (long)0;
! 	else
! 		l = strtol(s, &badp, 10);
  	if (errno)					/* strtol must set ERANGE */
  		elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
  	if (badp && *badp && (*badp != c))
#2Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Billy G. Allie (#1)
Re: [HACKERS] postgreSQL 6.4 patches.

Applied.

The pg_atoi() function uses strtol() to convert the string to numbers. Some
implementations of strtol() treat empty strings ("") as invalid arguments
while others convert this (erroneously, IHMO) to zero (0). Assuming that the
expected behaviour of pg_atoi() is to return 0 if it is passed an empty
string, I am supplying the following patch to explictly check for an empty
string in pg_atoi() and return 0 if the string is empty. The patch will also
trap a NULL character pointer being passed to pg_atoi() and will use elog() to
print out an error message if the input char pointer is NULL.

Content-Description: uw7p4.patch

[Attachment, skipping...]

____ | Billy G. Allie | Domain....: Bill.Allie@mug.org
| /| | 7436 Hartwell | Compuserve: 76337,2061
|-/-|----- | Dearborn, MI 48126| MSN.......: B_G_Allie@email.msn.com
|/ |LLIE | (313) 582-1540 |

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)