Fix stack buffer overflow in Vgetname/Vgetclass/Vinquire - #901
Draft
bmribler wants to merge 5 commits into
Draft
Conversation
bmribler
requested review from
brtnfld,
byrnHDF,
derobins,
fortnern,
glennsong09,
jhendersonHDF,
lrknox,
mattjala,
schwehr and
vchoi-hdfgroup
as code owners
August 23, 2026 23:26
bmribler
marked this pull request as draft
August 23, 2026 23:32
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
force-pushed
the
fix_hdf_getters_final
branch
from
August 24, 2026 05:17
b860b0e to
e84565c
Compare
bmribler
marked this pull request as ready for review
August 24, 2026 11:18
bmribler
marked this pull request as draft
August 24, 2026 20:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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