]> sourceware.org Git - newlib-cygwin.git/commit
Cygwin: Avoid use-after-free warnings in __set_lc_time_from_win() etc.
authorJon Turney <jon.turney@dronecode.org.uk>
Sun, 4 Aug 2024 16:15:50 +0000 (17:15 +0100)
committerJon Turney <jon.turney@dronecode.org.uk>
Tue, 13 Aug 2024 18:44:00 +0000 (19:44 +0100)
commit4eb9397b6ccc725820143fbdf5feb3f62306440b
tree88905ad665e072282b6ca3707bcd77ed00e1b351
parent80e7ed9383953c1bcd6f57c8b23257c04f597d3d
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 <jon.turney@dronecode.org.uk>
winsup/cygwin/nlsfuncs.cc
This page took 0.028857 seconds and 5 git commands to generate.