Page MenuHomeFreeBSD

Fix undefined behavior when using asmc_fan_getstring()
ClosedPublic

Authored by uqs on Dec 30 2015, 12:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 16, 10:59 PM
Unknown Object (File)
Thu, Mar 21, 10:43 PM
Unknown Object (File)
Thu, Mar 21, 10:43 PM
Unknown Object (File)
Feb 12 2024, 4:24 PM
Unknown Object (File)
Jan 18 2024, 11:23 AM
Unknown Object (File)
Jan 18 2024, 11:23 AM
Unknown Object (File)
Dec 20 2023, 12:33 AM
Unknown Object (File)
Dec 11 2023, 1:11 AM
Subscribers

Details

Reviewers
rpaulo
ed
Summary

It was returning a pointer to stack-allocated memory, so make the
allocation at the caller instead.

Found by: clang static analyzer

Diff Detail

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

Event Timeline

uqs retitled this revision from to Fix undefined behavior when using asmc_fan_getstring().
uqs updated this object.
uqs edited the test plan for this revision. (Show Details)
uqs added a reviewer: rpaulo.
ed added a reviewer: ed.
ed added a subscriber: ed.
ed added inline comments.
sys/dev/asmc/asmc.c
966

Maybe use size_t buflen? If asmc_key_read() uses int anyway, just leave it the way it is.

1020

sizeof(buf) per style(9).

This revision is now accepted and ready to land.Jan 4 2016, 8:52 PM
uqs edited edge metadata.
uqs marked an inline comment as done.

Change type and style(9)

This revision now requires review to proceed.Jan 4 2016, 9:12 PM
ed edited edge metadata.
This revision is now accepted and ready to land.Jan 4 2016, 9:20 PM
rpaulo edited edge metadata.

committed

sys/dev/asmc/asmc.c
966

Yeah, I of course had size_t first, but realistically a char would suffice. I wanted to keep it as a 32bit int for the minor savings for LP64 platforms.

http://bxr.su/FreeBSD/sys/dev/asmc/asmc.c#717

asmc_key_read(device_t dev, const char *key, uint8_t *buf, uint8_t len)

so maybe use uint8_t as well?