Skip to content

Fix stack buffer overflow in Vgetname/Vgetclass/Vinquire - #901

Draft
bmribler wants to merge 5 commits into
HDFGroup:masterfrom
bmribler:fix_hdf_getters_final
Draft

Fix stack buffer overflow in Vgetname/Vgetclass/Vinquire#901
bmribler wants to merge 5 commits into
HDFGroup:masterfrom
bmribler:fix_hdf_getters_final

Conversation

@bmribler

@bmribler bmribler commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Vgetname, Vgetclass, and Vinquire performed unbounded strcpy into caller-supplied buffers with no length parameter, allowing stack buffer overflows on names/classes longer than the caller anticipated.

Each function now takes a buf_size parameter and returns the actual name/class length on success or FAIL on error, using ptrdiff_t (instead of ssize_t) as the return type for Windows portability without a POSIX-type workaround. This makes Vgetnamelen and Vgetclassnamelen redundant, so they're removed.

Two utility functions were added, vgetvgname/vgetvgclass. They return the name/class of a vgroup, allocating the buffer internally so the caller does not need to know the length of the name/class in advance. Strictly intended for use within the library and tools only by including the private header file vg_priv.h; the caller is responsible for freeing the returned buffer.

BREAKING: callers must update call sites to pass buf_size to any of these three functions and replace the calls to Vgetnamelen/Vgetclassnamelen by the appropriate Vgetname/Vgetclass calls, passing in 0 and NULL for buffer size and buffer.

Fixes #872

Fixes HDFGroup#872

- Adds buf_size parameter to prevent unbounded strcpy into caller buffers
- These functions now double as getting the length of the vgroup name or class, replacing Vgetnamelen/Vgetclassnamelen
- Adds internal vgetvgname/vgetvgclass utilities in vg_priv.h for use throughout the library and tools
- Updates Java API
- Updates Fortran API
@bmribler
bmribler force-pushed the fix_hdf_getters_final branch from b860b0e to e84565c Compare August 24, 2026 05:17
@bmribler
bmribler marked this pull request as ready for review August 24, 2026 11:18
@bmribler
bmribler marked this pull request as draft August 24, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component - C Library Core C library issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack buffer overflow in Vgetname, Vgetclass, and Vinquire via unbounded strcpy (CWE-121/CWE-787)

1 participant