Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b4bf51

Browse files
committed
ecpg: fix some minor mishandling of bad input in preprocessor.
Avoid null-pointer crash when considering a cursor declarationthat's outside any C function (a case which is useless anyway).Ensure a cursor for a prepared statement is marked as initiallynot open. At worst, if we chanced to get not-already-zeroed memoryfrom malloc(), this oversight would result in failing to issue a"cursor "foo" has been declared but not opened" warning that wouldhave been appropriate.Avoid running off the end of the buffer when there are mismatchedsquare brackets following a variable name. This could lead toSIGSEGV after reaching the end of memory.Given the lack of field complaints, none of these seem to be worthback-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 parent79fa7b3 commit9b4bf51

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)

[8]ページ先頭

©2009-2025 Movatter.jp