Skip to content

Commit

Permalink
unistr.c: Fix use-after-free in 'ntfs_uppercase_mbs'.
Browse files Browse the repository at this point in the history
If 'utf8_to_unicode' throws an error due to an invalid UTF-8 sequence,
then 'n' will be less than 0 and the loop will terminate without storing
anything in '*t'. After the loop the uppercase string's allocation is
freed, however after it is freed it is unconditionally accessed through
'*t', which points into the freed allocation, for the purpose of NULL-
terminating the string. This leads to a use-after-free.
Fixed by only NULL-terminating the string when no error has been thrown.

Thanks for Jeffrey Bencteux for reporting this issue:
#84
  • Loading branch information
unsound committed Jun 13, 2023
1 parent 6b3f096 commit 75dcdc2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libntfs-3g/unistr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,9 @@ char *ntfs_uppercase_mbs(const char *low,
free(upp);
upp = (char*)NULL;
errno = EILSEQ;
} else {
*t = 0;
}
*t = 0;
}
return (upp);
}
Expand Down

0 comments on commit 75dcdc2

Please sign in to comment.