mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 10:30:33 +03:00 
			
		
		
		
	Adjust the behavior of the PQExpBuffer code to make it have well-defined
results (ie, an empty "broken" buffer) if memory overrun occurs anywhere along the way to filling the buffer. The previous coding would just silently discard portions of the intended buffer contents, as exhibited in trouble report from Sam Mason. Also, tweak psql's main loop to correctly detect and report such overruns. There's probably much more that should be done in this line, but this is a start.
This commit is contained in:
		| @@ -3,7 +3,7 @@ | ||||
|  * | ||||
|  * Copyright (c) 2000-2008, PostgreSQL Global Development Group | ||||
|  * | ||||
|  * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.64 2008/01/01 19:45:56 momjian Exp $ | ||||
|  * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.65 2008/11/26 00:26:23 tgl Exp $ | ||||
|  */ | ||||
| #include "postgres_fe.h" | ||||
|  | ||||
| @@ -184,7 +184,8 @@ gets_fromFile(FILE *source) | ||||
| 		{ | ||||
| 			if (ferror(source)) | ||||
| 			{ | ||||
| 				psql_error("could not read from input file: %s\n", strerror(errno)); | ||||
| 				psql_error("could not read from input file: %s\n", | ||||
| 						   strerror(errno)); | ||||
| 				return NULL; | ||||
| 			} | ||||
| 			break; | ||||
| @@ -192,6 +193,12 @@ gets_fromFile(FILE *source) | ||||
|  | ||||
| 		appendPQExpBufferStr(buffer, line); | ||||
|  | ||||
| 		if (PQExpBufferBroken(buffer)) | ||||
| 		{ | ||||
| 			psql_error("out of memory\n"); | ||||
| 			return NULL; | ||||
| 		} | ||||
|  | ||||
| 		/* EOL? */ | ||||
| 		if (buffer->data[buffer->len - 1] == '\n') | ||||
| 		{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user