Skip to content

Commit 9b4bf51

Browse files
committed
ecpg: fix some minor mishandling of bad input in preprocessor.
Avoid null-pointer crash when considering a cursor declaration that's outside any C function (a case which is useless anyway). Ensure a cursor for a prepared statement is marked as initially not open. At worst, if we chanced to get not-already-zeroed memory from malloc(), this oversight would result in failing to issue a "cursor "foo" has been declared but not opened" warning that would have been appropriate. Avoid running off the end of the buffer when there are mismatched square brackets following a variable name. This could lead to SIGSEGV after reaching the end of memory. Given the lack of field complaints, none of these seem to be worth back-patching, but let's clean them up in HEAD. Per valgrind testing by Alexander Lakhin. Discussion: https://postgr.es/m/5f5bcecd-d7ec-b8c0-6c92-d1a7c6e0f639@gmail.com
1 parent 79fa7b3 commit 9b4bf51

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/interfaces/ecpg/preproc/ecpg.header

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
432432
/* This tests whether the cursor was declared and opened in the same function. */
433433
#define SAMEFUNC(cur) \
434434
((cur->function == NULL) || \
435-
(cur->function != NULL && strcmp(cur->function, current_function) == 0))
435+
(cur->function != NULL && current_function != NULL && \
436+
strcmp(cur->function, current_function) == 0))
436437

437438
static struct cursor *
438439
add_additional_variables(const char *name, bool insert)

src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ ECPGCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared_
433433
this->name = mm_strdup(@2);
434434
this->function = (current_function ? mm_strdup(current_function) : NULL);
435435
this->connection = connection ? mm_strdup(connection) : NULL;
436+
this->opened = false;
436437
this->command = mm_strdup(cat_str(6, "declare", cursor_marker, @3, "cursor", @5, "for $1"));
437438
this->argsresult = NULL;
438439
this->argsresult_oos = NULL;

src/interfaces/ecpg/preproc/variable.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ find_variable(const char *name)
216216
case ']':
217217
count--;
218218
break;
219+
case '\0':
220+
mmfatal(PARSE_ERROR, "unmatched brace in variable \"%s\"", name);
221+
break;
219222
default:
220223
break;
221224
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy