Page MenuHomeFreeBSD

Fix undefined behavior when using asmc_fan_getstring()
ClosedPublic

Authored by uqs on Dec 30 2015, 12:08 PM.

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
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 1948
Build 1955: arc lint + arc unit

Event Timeline

uqs updated this revision to Diff 11792.Dec 30 2015, 12:08 PM
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 accepted this revision.Jan 4 2016, 8:52 PM
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 updated this revision to Diff 11924.Jan 4 2016, 9:12 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 accepted this revision.Jan 4 2016, 9:20 PM
ed edited edge metadata.
This revision is now accepted and ready to land.Jan 4 2016, 9:20 PM
rpaulo accepted this revision.Jan 5 2016, 3:06 AM
rpaulo edited edge metadata.
uqs closed this revision.Jan 5 2016, 12:09 PM

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?