1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-24 10:47:04 +03:00

Fixed a buffer overrun that was masked on Linux systems.

This commit is contained in:
Michael Meskes 2006-08-18 16:30:53 +00:00
parent 121dd1cdf5
commit 46d61eb218
4 changed files with 40 additions and 36 deletions

View File

@ -2095,11 +2095,13 @@ Mo Aug 14 10:39:59 CEST 2006
- Fixed broken newline on Windows. - Fixed broken newline on Windows.
- Fixed a nasty buffer underrun that only occured when using Informix - Fixed a nasty buffer underrun that only occured when using Informix
no_indicator NULL setting on timestamps and intervals. no_indicator NULL setting on timestamps and intervals.
<<<<<<< ChangeLog
Fr 18. Aug 17:32:54 CEST 2006 Fr 18. Aug 17:32:54 CEST 2006
- Changed lexer to no longer use the default rule. - Changed lexer to no longer use the default rule.
- Synced parser and keyword list. - Synced parser and keyword list.
- Fixed parsing of CONNECT statement so it accepts a C string again. - Fixed parsing of CONNECT statement so it accepts a C string again.
- Fixed a buffer overrun that was masked on Linux systems.
- Set ecpg library version to 5.2. - Set ecpg library version to 5.2.
- Set ecpg version to 4.2.1. - Set ecpg version to 4.2.1.

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.58 2006/08/09 09:08:31 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.59 2006/08/18 16:30:53 meskes Exp $ */
/* /*
* The aim is to get a simpler inteface to the database routines. * The aim is to get a simpler inteface to the database routines.
@ -572,19 +572,21 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
} }
if (**tobeinserted_p == '\0') if (**tobeinserted_p == '\0')
{ {
int asize = var->arrsize? var->arrsize : 1;
switch (var->type) switch (var->type)
{ {
int element; int element;
case ECPGt_short: case ECPGt_short:
if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -597,14 +599,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_int: case ECPGt_int:
if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -617,14 +619,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_unsigned_short: case ECPGt_unsigned_short:
if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -637,14 +639,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_unsigned_int: case ECPGt_unsigned_int:
if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -657,14 +659,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_long: case ECPGt_long:
if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -677,14 +679,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_unsigned_long: case ECPGt_unsigned_long:
if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -697,14 +699,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
#ifdef HAVE_LONG_LONG_INT_64 #ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long: case ECPGt_long_long:
if (!(mallocedval = ECPGalloc(var->arrsize * 30, lineno))) if (!(mallocedval = ECPGalloc(asize * 30, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -717,14 +719,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_unsigned_long_long: case ECPGt_unsigned_long_long:
if (!(mallocedval = ECPGalloc(var->arrsize * 30, lineno))) if (!(mallocedval = ECPGalloc(asize * 30, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -737,14 +739,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
#endif /* HAVE_LONG_LONG_INT_64 */ #endif /* HAVE_LONG_LONG_INT_64 */
case ECPGt_float: case ECPGt_float:
if (!(mallocedval = ECPGalloc(var->arrsize * 25, lineno))) if (!(mallocedval = ECPGalloc(asize * 25, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@ -757,14 +759,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
break; break;
case ECPGt_double: case ECPGt_double:
if (!(mallocedval = ECPGalloc(var->arrsize * 25, lineno))) if (!(mallocedval = ECPGalloc(asize * 25, lineno)))
return false; return false;
if (var->arrsize > 1) if (asize > 1)
{ {
strcpy(mallocedval, "array ["); strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++) for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]); sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]"); strcpy(mallocedval + strlen(mallocedval) - 1, "]");

View File

@ -27,7 +27,7 @@ EXEC SQL BEGIN DECLARE SECTION;
int *did = &i; int *did = &i;
int a[10] = {9,8,7,6,5,4,3,2,1,0}; int a[10] = {9,8,7,6,5,4,3,2,1,0};
char text[25] = "klmnopqrst"; char text[25] = "klmnopqrst";
char *t = (char *)malloc(10); char *t = (char *)malloc(11);
double f; double f;
bool b = true; bool b = true;
EXEC SQL END DECLARE SECTION; EXEC SQL END DECLARE SECTION;

View File

@ -140,7 +140,7 @@ main (void)
char text [ 25 ] = "klmnopqrst" ; char text [ 25 ] = "klmnopqrst" ;
#line 30 "test4.pgc" #line 30 "test4.pgc"
char * t = ( char * ) malloc ( 10 ) ; char * t = ( char * ) malloc ( 11 ) ;
#line 31 "test4.pgc" #line 31 "test4.pgc"
double f ; double f ;