Skip to content

Commit 820f9f8

Browse files
committed
Fix potential coredump in pg_conndefaults (assigning constant string
to a field that will get free'd). Also make it robust in cases where values contain Tcl special characters.
1 parent 3f2fff5 commit 820f9f8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/interfaces/libpgtcl/pgtclCmds.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.36 1998/10/01 01:45:38 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.37 1998/10/02 01:37:17 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -240,21 +240,23 @@ int
240240
Pg_conndefaults(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
241241
{
242242
PQconninfoOption *option;
243-
char buf[8192];
243+
Tcl_DString result;
244+
char ibuf[32];
244245

245-
Tcl_ResetResult(interp);
246+
Tcl_DStringInit(&result);
246247
for (option = PQconndefaults(); option->keyword != NULL; option++)
247248
{
248-
if (option->val == NULL)
249-
option->val = "";
250-
sprintf(buf, "{%s} {%s} {%s} %d {%s}",
251-
option->keyword,
252-
option->label,
253-
option->dispchar,
254-
option->dispsize,
255-
option->val);
256-
Tcl_AppendElement(interp, buf);
257-
}
249+
char * val = option->val ? option->val : "";
250+
sprintf(ibuf, "%d", option->dispsize);
251+
Tcl_DStringStartSublist(&result);
252+
Tcl_DStringAppendElement(&result, option->keyword);
253+
Tcl_DStringAppendElement(&result, option->label);
254+
Tcl_DStringAppendElement(&result, option->dispchar);
255+
Tcl_DStringAppendElement(&result, ibuf);
256+
Tcl_DStringAppendElement(&result, val);
257+
Tcl_DStringEndSublist(&result);
258+
}
259+
Tcl_DStringResult(interp, &result);
258260

259261
return TCL_OK;
260262
}

0 commit comments

Comments
 (0)