HomeFreeBSD

pkg: Allocate a suitably-sized string for the local ABI

Description

pkg: Allocate a suitably-sized string for the local ABI

Previously the local ABI string was written to an on-stack buffer and
the pointer to that buffer was saved in a global before the function
returned. This had two issues: c[ABI].val pointed to a
no-longer-valid on-stack buffer after config_init returned, and the
string could potentially be truncated. Fix both of those by changing
pkg_get_myabi to return a pointer to a string allocated by asprintf.

Note that the allocated string is left in the global config array
until it is implicitly freed on process exit.

Reported by: GCC 13 -Wdangling-pointer
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D42623

(cherry picked from commit fd9ae9ac04edf9acef4a2ffbf663698a2b8e7ced)

Details

Provenance
jhbAuthored on Nov 16 2023, 12:53 AM
Reviewer
emaste
Differential Revision
D42623: pkg: Allocate a suitably-sized string for the local ABI
Parents
rG1d491430732e: snmp_wlan: Fix a couple of type mismatches in function prototypes
Branches
Unknown
Tags
Unknown