Skip to content

Commit 90e53f0

Browse files
author
Michael Meskes
committed
Fixed potentially uninitialized memory bug in compatlib.
1 parent 0637d52 commit 90e53f0

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,10 @@ Thu Oct 30 11:12:37 CET 2003
17051705
Fri Oct 31 15:09:22 CET 2003
17061706

17071707
- If EOF is found inside a string/comment/etc. stop parsing.
1708+
1709+
Mon Nov 3 15:43:19 CET 2003
1710+
1711+
- Fixed a potentially uncleared allocation in compatlib.
17081712
- Set ecpg version to 3.0.0
17091713
- Set ecpg library to 4.0.0
17101714
- Set pgtypes library to 1.0.0

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <errno.h>
44
#include <math.h>
55
#include <ctype.h>
6+
#include <limits.h>
67

78
#include <ecpgtype.h>
89
#include <compatlib.h>
@@ -11,7 +12,7 @@
1112
#include <pgtypes_numeric.h>
1213
#include <sqltypes.h>
1314

14-
char *ECPGalloc(long, int);
15+
char *ECPGalloc(long, int);
1516

1617
static int
1718
deccall2(decimal * arg1, decimal * arg2, int (*ptr) (numeric *, numeric *))
@@ -659,41 +660,50 @@ static struct
659660
} value;
660661

661662
/**
662-
* initialize the struct, wich holds the different forms
663+
* initialize the struct, which holds the different forms
663664
* of the long value
664665
*/
665666
static void
666-
initValue(long lng_val)
667-
{
668-
int i,
669-
div,
670-
dig;
671-
char tmp[2] = " ";
672-
673-
/* set some obvious things */
674-
value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
675-
value.sign = lng_val >= 0 ? '+' : '-';
676-
value.maxdigits = log10(2) * (8 * sizeof(long) - 1);
677-
678-
/* determine the number of digits */
679-
for (i = 0; i <= value.maxdigits; i++)
680-
{
681-
if ((int) (value.val / pow(10, i)) != 0)
682-
value.digits = i + 1;
683-
}
684-
value.remaining = value.digits;
685-
686-
/* convert the long to string */
687-
value.val_string = (char *) malloc(value.digits + 1);
688-
for (i = value.digits; i > 0; i--)
689-
{
690-
div = pow(10, i);
691-
dig = (value.val % div) / (div / 10);
692-
tmp[0] = (char) (dig + 48);
693-
strcat(value.val_string, tmp);
694-
}
695-
/* safety-net */
696-
value.val_string[value.digits] = '\0';
667+
initValue (long lng_val)
668+
{
669+
int i, j;
670+
long l, dig;
671+
672+
/* set some obvious things */
673+
value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
674+
value.sign = lng_val >= 0 ? '+' : '-';
675+
value.maxdigits = log10 (2) * (8 * sizeof (long) - 1);
676+
677+
/* determine the number of digits */
678+
i = 0;
679+
l = 1;
680+
do
681+
{
682+
i++;
683+
l *= 10;
684+
}
685+
while ((l - 1) < value.val && l <= LONG_MAX / 10);
686+
687+
if (l <= LONG_MAX/10)
688+
{
689+
value.digits = i;
690+
l /= 10;
691+
}
692+
else
693+
value.digits = i + 1;
694+
695+
value.remaining = value.digits;
696+
697+
/* convert the long to string */
698+
value.val_string = (char *) malloc (value.digits + 1);
699+
dig = value.val;
700+
for (i = value.digits, j = 0; i > 0; i--, j++)
701+
{
702+
value.val_string[j] = dig/l + '0';
703+
dig = dig % l;
704+
l /= 10;
705+
}
706+
value.val_string[value.digits] = '\0';
697707
}
698708

699709
/* return the position oft the right-most dot in some string */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy