Skip to content

Commit

Permalink
Improved memory management in the following BBF functions
Browse files Browse the repository at this point in the history
pltsql_post_expand_star
TdsSendTypeNumeric
pre_transform_target_entry
get_original_login_name

Task: BABEL-4455, BABEL-4445, BABEL-4448, BABEL-4454
Signed-off-by: Kristian Lejao <[email protected]>
  • Loading branch information
lejaokri committed Oct 9, 2023
1 parent ac99472 commit ed8169f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 5 additions & 2 deletions contrib/babelfishpg_tds/src/backend/tds/tdstypeio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,8 @@ TdsSendTypeNumeric(FmgrInfo *finfo, Datum value, void *vMetaData)
{
int rc = EOF,
precision = 0,
scale = -1;
scale = -1,
outlen = 0;
uint8 sign = 1,
length = 0;
char *out,
Expand All @@ -3057,7 +3058,8 @@ TdsSendTypeNumeric(FmgrInfo *finfo, Datum value, void *vMetaData)
* response string is formatted to obtain string representation of TDS
* unsigned integer along with its precision and scale
*/
decString = (char *) palloc(sizeof(char) * (strlen(out) + 1));
outlen = strlen(out) + max_scale;
decString = (char *) palloc(sizeof(char) * (outlen + 1));
/* While there is still digit in out and we haven't reached max_scale */
while (*out && scale < max_scale)
{
Expand Down Expand Up @@ -3090,6 +3092,7 @@ TdsSendTypeNumeric(FmgrInfo *finfo, Datum value, void *vMetaData)
decString[precision++] = '0';
}
decString[precision] = '\0';
Assert(precision <= outlen);

if (precision > TDS_MAX_NUM_PRECISION ||
precision > max_precision)
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate,
/* Identifier is not truncated. */
else
{
memcpy(alias, original_name, alias_len);
memcpy(alias, original_name, actual_alias_len);
}
res->name = alias;

Expand Down
7 changes: 2 additions & 5 deletions contrib/babelfishpg_tsql/src/pl_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1551,8 +1551,7 @@ pltsql_post_expand_star(ParseState *pstate, ColumnRef *cref, List *l)
Datum *optiondatums;
int noptions,
i;
char *optstr,
*bbf_original_name;
char *optstr;

foreach(li, l)
{
Expand Down Expand Up @@ -1605,9 +1604,7 @@ pltsql_post_expand_star(ParseState *pstate, ColumnRef *cref, List *l)
/*
* We found the original name; rewrite it as bbf_original_name
*/
bbf_original_name = &optstr[18];
bbf_original_name[strlen(te->resname)] = '\0';
te->resname = pstrdup(bbf_original_name);
te->resname = pnstrdup((char *) &optstr[18], strlen(te->resname));
break;
}
}
Expand Down

0 comments on commit ed8169f

Please sign in to comment.