Skip to content

Commit 089c581

Browse files
almkuznetsovCommitfest Bot
authored andcommitted
Detect buffer underflow in get_th()
If get_th() can receive input that is not a number, then it can also receive empty input. Empty input with zero length can result in a buffer underflow when accessing *(num + (len - 1)), as (len - 1) would produce a negative index. Add a check for zero-length input to prevent it. This was found by ALT Linux Team.
1 parent 12efa48 commit 089c581

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/backend/utils/adt/formatting.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,11 @@ get_th(char *num, int type)
15651565
int len = strlen(num),
15661566
last;
15671567

1568+
if (len == 0)
1569+
ereport(ERROR,
1570+
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
1571+
errmsg("input cannot be empty string")));
1572+
15681573
last = *(num + (len - 1));
15691574
if (!isdigit((unsigned char) last))
15701575
ereport(ERROR,

0 commit comments

Comments
 (0)