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

Commit67fb608

Browse files
committed
Guard against empty buffer in gets_fromFile()'s check for a newline.
Per the fgets() specification, it cannot return without reading some dataunless it reports EOF or error. So the code here assumed that the databuffer would necessarily be nonempty when we go to check for a newlinehaving been read. However, Agostino Sarubbo noticed that this could failto be true if the first byte of the data is a NUL (\0). The fgets() APIdoesn't really work for embedded NULs, which is something I don't feelany great need for us to worry about since we generally don't allow NULsin SQL strings anyway. But we should not access off the end of our ownbuffer if the case occurs. Normally this would just be a harmless read,but if you were unlucky the byte before the buffer would contain '\n'and we'd overwrite it with '\0', and if you were really unlucky thatmight be valuable data and psql would crash.Agostino reported this to pgsql-security, but after discussion we concludedthat it isn't worth treating as a security bug; if you can control theinput to psql you can do far more interesting things than just maybe-crashit. Nonetheless, it is a bug, so back-patch to all supported versions.
1 parent1e2f96f commit67fb608

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎src/bin/psql/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ gets_fromFile(FILE *source)
218218
}
219219

220220
/* EOL? */
221-
if (buffer->data[buffer->len-1]=='\n')
221+
if (buffer->len>0&&buffer->data[buffer->len-1]=='\n')
222222
{
223223
buffer->data[buffer->len-1]='\0';
224224
returnpg_strdup(buffer->data);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp