[PATCH] common: misc: support strerror(err) for all err <= MAX_ERRNO

Sascha Hauer s.hauer at pengutronix.de
Mon Sep 28 04:28:31 EDT 2020


On Mon, Sep 21, 2020 at 09:11:35AM +0200, Ahmad Fatoum wrote:
> We have a _LAST_ERRNO of 3 decimal digits. strerror(_LAST_ERRNO) is ok,
> but it's still possible that some code passes a non-error code int,
> which will overflow the static buffer. Play it safe and bump up the
> buffer size to at least 11 characters. This is enough to represent
> all integers, with only 7 characters more static storage.
> 
> This way strerror(some_int_passed_by_mistake) will not invoke UB.
> 
> Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
> ---
> Detected by ASAN on sandbox a while ago. The place which passed the
> non-errno int needs probably fixing as well, but I need to find it again
> first..
> ---
>  common/misc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list