提交 820f9f8b 编写于 作者: T Tom Lane

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.
上级 3f2fff5c
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.36 1998/10/01 01:45:38 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.37 1998/10/02 01:37:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -240,21 +240,23 @@ int ...@@ -240,21 +240,23 @@ int
Pg_conndefaults(ClientData cData, Tcl_Interp * interp, int argc, char **argv) Pg_conndefaults(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
{ {
PQconninfoOption *option; PQconninfoOption *option;
char buf[8192]; Tcl_DString result;
char ibuf[32];
Tcl_ResetResult(interp); Tcl_DStringInit(&result);
for (option = PQconndefaults(); option->keyword != NULL; option++) for (option = PQconndefaults(); option->keyword != NULL; option++)
{ {
if (option->val == NULL) char * val = option->val ? option->val : "";
option->val = ""; sprintf(ibuf, "%d", option->dispsize);
sprintf(buf, "{%s} {%s} {%s} %d {%s}", Tcl_DStringStartSublist(&result);
option->keyword, Tcl_DStringAppendElement(&result, option->keyword);
option->label, Tcl_DStringAppendElement(&result, option->label);
option->dispchar, Tcl_DStringAppendElement(&result, option->dispchar);
option->dispsize, Tcl_DStringAppendElement(&result, ibuf);
option->val); Tcl_DStringAppendElement(&result, val);
Tcl_AppendElement(interp, buf); Tcl_DStringEndSublist(&result);
} }
Tcl_DStringResult(interp, &result);
return TCL_OK; return TCL_OK;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册