mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -7,7 +7,7 @@ | ||||
|  * | ||||
|  * | ||||
|  * 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 | ||||
| Pg_conndefaults(ClientData cData, Tcl_Interp * interp, int argc, char **argv) | ||||
| { | ||||
| 	PQconninfoOption *option; | ||||
| 	char		buf[8192]; | ||||
| 	Tcl_DString result; | ||||
| 	char ibuf[32]; | ||||
|  | ||||
| 	Tcl_ResetResult(interp); | ||||
| 	Tcl_DStringInit(&result); | ||||
| 	for (option = PQconndefaults(); option->keyword != NULL; option++) | ||||
| 	{ | ||||
| 		if (option->val == NULL) | ||||
| 			option->val = ""; | ||||
| 		sprintf(buf, "{%s} {%s} {%s} %d {%s}", | ||||
| 				option->keyword, | ||||
| 				option->label, | ||||
| 				option->dispchar, | ||||
| 				option->dispsize, | ||||
| 				option->val); | ||||
| 		Tcl_AppendElement(interp, buf); | ||||
| 		char * val = option->val ? option->val : ""; | ||||
| 		sprintf(ibuf, "%d", option->dispsize); | ||||
| 		Tcl_DStringStartSublist(&result); | ||||
| 		Tcl_DStringAppendElement(&result, option->keyword); | ||||
| 		Tcl_DStringAppendElement(&result, option->label); | ||||
| 		Tcl_DStringAppendElement(&result, option->dispchar); | ||||
| 		Tcl_DStringAppendElement(&result, ibuf); | ||||
| 		Tcl_DStringAppendElement(&result, val); | ||||
| 		Tcl_DStringEndSublist(&result); | ||||
| 	} | ||||
| 	Tcl_DStringResult(interp, &result); | ||||
|  | ||||
| 	return TCL_OK; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user