Skip to content

Commit e39b856

Browse files
hongjinghaoH. Peter Anvin (Intel)
authored andcommitted
preproc: fix heap memory overflow CVE-2023-31722
paramlen has heap memory of length nparam+1. The value of variable i may be greater than nparam+1, causing heap memory overflow. Therefore, i and nparam+1 needs to be determined in the loop. Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392857#c1 Fixes: #83 Signed-off-by: H. Peter Anvin (Intel) <[email protected]>
1 parent c651c28 commit e39b856

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

asm/preproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7245,7 +7245,7 @@ static int expand_mmacro(Token * tline)
72457245
*/
72467246
nasm_newn(paramlen, nparam+1);
72477247

7248-
for (i = 1; (t = params[i]); i++) {
7248+
for (i = 1; i < nparam+1 && (t = params[i]); i++) {
72497249
bool braced = false;
72507250
int brace = 0;
72517251
int white = 0;

nasmlib/alloc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ void *nasm_realloc(void *q, size_t size)
7474

7575
void nasm_free(void *q)
7676
{
77-
if (q)
77+
if (q){
7878
free(q);
79+
q = NULL;
80+
}
7981
}
8082

8183
char *nasm_strdup(const char *s)

0 commit comments

Comments
 (0)