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

Commit3c18d90

Browse files
committed
Null-terminate the output buffer of LZ4Stream_gets
LZ4Stream_gets did not null-terminate its output buffer. The callers expectedthe buffer to be null-terminated and passed it around to functions such assscanf with unintended consequences.Author: Georgios Kokolatos <gkokolatos@pm.me>Reported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/94ae9bca-5ebb-1e68-bb7b-4f32e89fefbe@gmail.com
1 parentd8c3106 commit3c18d90

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

‎src/bin/pg_dump/compress_lz4.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ LZ4Stream_read_internal(LZ4State *state, void *ptr, int ptrsize, bool eol_flag)
459459
if (!LZ4Stream_init(state,size, false/* decompressing */ ))
460460
return-1;
461461

462+
/* No work needs to be done for a zero-sized output buffer */
463+
if (size <=0)
464+
return0;
465+
462466
/* Verify that there is enough space in the outbuf */
463467
if (size>state->buflen)
464468
{
@@ -636,14 +640,20 @@ LZ4Stream_gets(char *ptr, int size, CompressFileHandle *CFH)
636640
LZ4State*state= (LZ4State*)CFH->private_data;
637641
intret;
638642

639-
ret=LZ4Stream_read_internal(state,ptr,size, true);
643+
ret=LZ4Stream_read_internal(state,ptr,size-1, true);
640644
if (ret<0|| (ret==0&& !LZ4Stream_eof(CFH)))
641645
pg_fatal("could not read from input file: %s",LZ4Stream_get_error(CFH));
642646

643647
/* Done reading */
644648
if (ret==0)
645649
returnNULL;
646650

651+
/*
652+
* Our caller expects the return string to be NULL terminated
653+
* and we know that ret is greater than zero.
654+
*/
655+
ptr[ret-1]='\0';
656+
647657
returnptr;
648658
}
649659

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp