-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cygwin: Avoid use-after-free warnings in __set_lc_time_from_win() etc.
Rewrite to avoid new use-after-free warnings about realloc(), seen with gcc 12, e.g.: > In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’, > inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25: > ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free] > 338 | *ptrs += newbase - oldbase; > | ~~~~~~~~^~~~~~~~~ > ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’: > ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here > 699 | char *tmp = (char *) realloc (new_lc_time_buf, len); Technically, it's UB to later refer to the realloced pointer (even just for offset computations, without deferencing it), so switch to using malloc() to create the resized copy. Signed-off-by: Jon Turney <[email protected]>
- Loading branch information
1 parent
80e7ed9
commit 4eb9397
Showing
1 changed file
with
41 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters