Bug 278128 - Use of uninitialized memory in libcam
Summary: Use of uninitialized memory in libcam
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-02 11:49 UTC by Peter Eriksson
Modified: 2024-04-02 11:50 UTC (History)
0 users

See Also:


Attachments
Patch to fix a warning about unitialized memory usage in libcam (305 bytes, patch)
2024-04-02 11:50 UTC, Peter Eriksson
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Eriksson 2024-04-02 11:49:40 UTC
While running valgrind on a small tool I noticed a warning/problem it detected in /usr/src/lib/libcam/camlib.c (cam_open_device->cam_lookup_pass->ioctl):

==61793== Memcheck, a memory error detector
==61793== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==61793== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==61793== Command: ./drvlist -v
==61793== 
==61793== Syscall param ioctl(generic) points to uninitialised byte(s)
==61793==    at 0x4A0536A: ioctl (in /lib/libc.so.7)
==61793==    by 0x206977: cam_lookup_pass (camlib.c:450)
==61793==    by 0x206882: cam_open_device (camlib.c:266)
==61793==    by 0x204D84: do_device (drvlist.c:398)
==61793==    by 0x2059A3: main (drvlist.c:604)
==61793==  Address 0x1ffbffee10 is on thread 1's stack
==61793==  in frame #1, created by cam_lookup_pass (camlib.c:421)
==61793==  Uninitialised value was created by a stack allocation
==61793==    at 0x2068A4: cam_lookup_pass (camlib.c:421)

The problem is that cam_lookup_pass() doesn't fully initialize the ccb struct before calling ioctl(). Probably not a big issue, but to get rid of that warning a simple memset(&ccb, 0, sizeof(ccb)) before the code that initialize it is needed.
Comment 1 Peter Eriksson 2024-04-02 11:50:49 UTC
Created attachment 249657 [details]
Patch to fix a warning about unitialized memory usage in libcam