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

Commite631ed8

Browse files
committed
Guard against enormously long input in pg_saslprep().
Coverity complained that pg_saslprep() could suffer integer overflow,leading to under-allocation of the output buffer, if the input stringexceeds SIZE_MAX/4. This hazard seems largely hypothetical, but it'seasy enough to defend against, so let's do so.This patch creates a third place in src/common/ where we are locallydefining MaxAllocSize so that we can test against that in the same wayin backend and frontend compiles. That seems like about two placestoo many, so the next patch will move that into common/fe_memutils.h.I'm hesitant to do that in back branches however.Back-patch to v14. The code looks similar in older branches, butbefore commit67a472d there was a separate test on the input stringlength that prevented this hazard.Per Coverity report.
1 parent22b9141 commite631ed8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎src/common/saslprep.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
*/
2222
#ifndefFRONTEND
2323
#include"postgres.h"
24+
#include"utils/memutils.h"
2425
#else
2526
#include"postgres_fe.h"
27+
28+
/* It's possible we could use a different value for this in frontend code */
29+
#defineMaxAllocSize((Size) 0x3fffffff)/* 1 gigabyte - 1 */
30+
2631
#endif
2732

2833
#include"common/saslprep.h"
@@ -1077,6 +1082,8 @@ pg_saslprep(const char *input, char **output)
10771082
input_size=pg_utf8_string_len(input);
10781083
if (input_size<0)
10791084
returnSASLPREP_INVALID_UTF8;
1085+
if (input_size >=MaxAllocSize /sizeof(pg_wchar))
1086+
gotooom;
10801087

10811088
input_chars=ALLOC((input_size+1)*sizeof(pg_wchar));
10821089
if (!input_chars)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp