Skip to content

Commit b991c92

Browse files
tds: fix potential NULL dereference
The result of the realloc function can be NULL if the memory allocation fails. Found by PostgresPro with Svace Static Analyzer Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>
1 parent dfd9085 commit b991c92

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/tds/token.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,13 @@ tds_alloc_get_string(TDSSOCKET * tds, char **string, size_t len)
25412541
*string = NULL;
25422542
return -1;
25432543
}
2544-
s = (char*) realloc(s, out_len + 1);
2544+
char *tmp = (char*) realloc(s, out_len + 1);
2545+
if (!tmp) {
2546+
free(s);
2547+
*string = NULL;
2548+
return -1;
2549+
}
2550+
s = tmp;
25452551
s[out_len] = '\0';
25462552
*string = s;
25472553
return 0;

0 commit comments

Comments
 (0)