Bug 198377 - libc: Invalid size check in load_msgcat()
Summary: libc: Invalid size check in load_msgcat()
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-03-06 23:35 UTC by Pedro F. Giffuni
Modified: 2017-01-12 00:32 UTC (History)
2 users (show)

See Also:


Attachments
Fix (470 bytes, patch)
2015-03-06 23:35 UTC, Pedro F. Giffuni
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro F. Giffuni freebsd_committer freebsd_triage 2015-03-06 23:35:26 UTC
Created attachment 153941 [details]
Fix

According to coverity 1193663, the following check always yields a false result:


405	if (st.st_size > SIZE_T_MAX) {
406		_close(fd);
407		SAVEFAIL(name, lang, EFBIG);
408		NLRETERR(EFBIG);
409	}
_____

result_independent_of_operands: st.st_size > 18446744073709551615ULL is always false regardless of the values of its operands. This occurs as the logical operand of if.


We can workaround this by excluding also SIZE_T_MAX but we should also exclude negative values since that would indicate an overflow.
Comment 1 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-03-06 23:36:21 UTC
Add Gabor since he is the author of the code.
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-03-06 23:37:24 UTC
Forgot to mention the code in question is in lib/libc/nls/msgcat.c
Comment 3 Conrad Meyer freebsd_committer freebsd_triage 2017-01-12 00:05:45 UTC
This Coverity warning is sort of dubious.  It's true on our 64-bit architectures, where sizeof(size_t) == sizeof(off_t); but it's not true on our 32-bit architectures, where size_t is half as big.

I think we should just ignore the CID in Coverity and move on.

It would be a pretty major OS bug for st_size to ever be negative, so I don't like the proposed patch.  If you want to add a KASSERT to sys_stat or kern_stat that st_size is >= 0, I would support that instead.
Comment 4 Pedro F. Giffuni freebsd_committer freebsd_triage 2017-01-12 00:32:06 UTC
Hmm ... yes, this is really old ... I think we could do an #ifdef trickery to work around the coverity report but it is probably not worth it.

Thanks for looking.