Page MenuHomeFreeBSD

mpool/mpool_get.c: Avoid clobbering 'errno' when handling 'pread' errors
ClosedPublic

Authored by bnovkov on Mon, Feb 23, 3:51 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 2, 12:55 AM
Unknown Object (File)
Sun, Mar 1, 2:23 PM
Unknown Object (File)
Sun, Mar 1, 3:32 AM
Unknown Object (File)
Sun, Mar 1, 2:26 AM
Unknown Object (File)
Sun, Mar 1, 2:25 AM
Unknown Object (File)
Sun, Mar 1, 2:17 AM
Unknown Object (File)
Wed, Feb 25, 7:17 PM
Unknown Object (File)
Wed, Feb 25, 1:37 PM
Subscribers

Details

Summary

POSIX.1-2024 states that the 'free' function "shall not modify errno if
ptr is a null pointer or a pointer previously returned as if by malloc()
and not yet deallocated". However this is a fairly recent addition
and non-compliant allocators might still clobber 'errno', causing
'mpool_get' to return the wrong error code. Fix this by saving
and restoring 'errno' after calling 'free'.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

obiwac added inline comments.
lib/libc/db/mpool/mpool.c
236–241

here there's not really a point in saving errno if we're going to set it to EINVAL anyways

Remove redundant errno save

bnovkov added inline comments.
lib/libc/db/mpool/mpool.c
236–241

whoops, pattern-matched a bit too greedily, thanks!

This revision is now accepted and ready to land.Mon, Feb 23, 5:59 PM