From: Michael Meskes Date: Fri, 18 Aug 2006 16:33:50 +0000 (+0000) Subject: Backported buffer overrun fix from HEAD X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=70c7f8cd349b1a1cdb66846ac3e76abee2b14b0f;p=users%2Fbernd%2Fpostgres.git Backported buffer overrun fix from HEAD --- diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 8fb38473be..08ea09369e 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -578,19 +578,21 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia } if (**tobeinserted_p == '\0') { + int asize = var->arrsize? var->arrsize : 1; + switch (var->type) { int element; case ECPGt_short: - if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) + if (!(mallocedval = ECPGalloc(asize * 20, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -603,14 +605,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_int: - if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) + if (!(mallocedval = ECPGalloc(asize * 20, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -623,14 +625,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_unsigned_short: - if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) + if (!(mallocedval = ECPGalloc(asize * 20, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -643,14 +645,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_unsigned_int: - if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) + if (!(mallocedval = ECPGalloc(asize * 20, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -663,14 +665,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_long: - if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) + if (!(mallocedval = ECPGalloc(asize * 20, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -683,14 +685,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_unsigned_long: - if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno))) + if (!(mallocedval = ECPGalloc(asize * 20, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -703,14 +705,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; #ifdef HAVE_LONG_LONG_INT_64 case ECPGt_long_long: - if (!(mallocedval = ECPGalloc(var->arrsize * 30, lineno))) + if (!(mallocedval = ECPGalloc(asize * 30, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -723,14 +725,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_unsigned_long_long: - if (!(mallocedval = ECPGalloc(var->arrsize * 30, lineno))) + if (!(mallocedval = ECPGalloc(asize * 30, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -743,14 +745,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; #endif /* HAVE_LONG_LONG_INT_64 */ case ECPGt_float: - if (!(mallocedval = ECPGalloc(var->arrsize * 25, lineno))) + if (!(mallocedval = ECPGalloc(asize * 25, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); @@ -763,14 +765,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia break; case ECPGt_double: - if (!(mallocedval = ECPGalloc(var->arrsize * 25, lineno))) + if (!(mallocedval = ECPGalloc(asize * 25, lineno))) return false; - if (var->arrsize > 1) + if (asize > 1) { 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]); strcpy(mallocedval + strlen(mallocedval) - 1, "]");