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
Unknown Object (File)
Dec 22 2023, 11:15 PM
Unknown Object (File)
Dec 12 2023, 4:40 AM
Unknown Object (File)
Nov 7 2023, 5:00 PM
Unknown Object (File)
Nov 7 2023, 6:07 AM
Unknown Object (File)
Oct 6 2023, 3:45 PM
Unknown Object (File)
Oct 6 2023, 5:03 AM
Unknown Object (File)
Sep 29 2023, 12:14 PM
Unknown Object (File)
Sep 25 2023, 3:22 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. :-)