Page MenuHomeFreeBSD

jedec_dimm: Use correct string length when populating sc->slotid_str
ClosedPublic

Authored by rpokala on Mar 22 2018, 1:12 AM.
Tags
None
Referenced Files
F154307142: D14790.diff
Mon, Apr 27, 5:59 PM
F154267274: D14790.id40578.diff
Mon, Apr 27, 12:09 PM
F154267268: D14790.id40578.diff
Mon, Apr 27, 12:09 PM
F154248686: D14790.id40587.diff
Mon, Apr 27, 9:45 AM
Unknown Object (File)
Thu, Apr 23, 2:01 PM
Unknown Object (File)
Fri, Apr 17, 3:37 PM
Unknown Object (File)
Fri, Apr 17, 6:20 AM
Unknown Object (File)
Thu, Apr 16, 5:15 PM
Subscribers

Details

Summary

Don't limit the copy to the size of the target string *pointer* (always
4 on 32-bit / 8 on 64-bit); limit the copy to the size of the target
string *buffer*.

THis is Coverity issue 1386912.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 15711
Build 15737: arc lint + arc unit

Event Timeline

sys/dev/jedec_dimm/jedec_dimm.c
346

don't need M_ZERO here. You are going to copy a string in and initialize every byte

@imp correctly observed that since the buffer is allocated to fit, then
fully initialized, there's no need to use M_ZERO.

cem added inline comments.
sys/dev/jedec_dimm/jedec_dimm.c
347

You could just use strdup(9) instead.

sys/dev/jedec_dimm/jedec_dimm.c
347

Had I known that it existed... :-S

(There is no strdup.9 file, or any str*.9 for that matter; as with much of libkern, we need documentation.)

Starting builds with that now. I also just realized why my earlier testing never hit the problem in the first place, so I'm going to do more extensive testing when I get home.

As @cem pointed out, it's even easier to use strdup().

what, no strdup.9 man page? Geeze :)

This is has now reached perfect: there's nothing left to take away.

This revision is now accepted and ready to land.Mar 22 2018, 5:54 AM
# Much longer than sizeof(sc->slotid_str)
% kenv hint.jedec_dimm.0.slotid
DIMM0LONGERSTRING

Before:

% sysctl dev.jedec_dimm.0.slotid
dev.jedec_dimm.0.slotid: DIMM0LO

After:

% sysctl dev.jedec_dimm.0.slotid
dev.jedec_dimm.0.slotid: DIMM0LONGERSTRING

Feel free to spend a bunch of time documenting libkern if you want. It's definitely valuable and shouldn't be too hard. Mostly just tedious. Maybe a thin document that just defines all of the libc-alike aliases and gets linked in a million places would be enough to start.

In D14790#311049, @cem wrote:

Feel free to spend a bunch of time documenting libkern if you want. It's definitely valuable and shouldn't be too hard. Mostly just tedious. Maybe a thin document that just defines all of the libc-alike aliases and gets linked in a million places would be enough to start.

Yeah. Different project for a different day. :-)