Skip to content

Add new APIs to address vulnerabilities in the V API#881

Closed
bmribler wants to merge 3 commits into
HDFGroup:masterfrom
bmribler:fix_name_functions
Closed

Add new APIs to address vulnerabilities in the V API#881
bmribler wants to merge 3 commits into
HDFGroup:masterfrom
bmribler:fix_name_functions

Conversation

@bmribler

@bmribler bmribler commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

The existing Vgroup APIs Vgetname, Vgetclass, and Vinquire posed multiple vulnerabilities due to the lack of size checks. Because changing their signature will break compatibilities, three new APIs are added in place of their deprecation instead. New APIs are:

int Vgetname40(int32 vkey, char *vgname, size_t *buf_size);
int Vgetclass40(int32 vkey, char *vgclass, size_t *buf_size);
int Vinquire40(int32 vkey, int32 *nentries, char *vgname, size_t *buf_size);

Fixes GH #872

The removed APIs are no longer needed with the new argument buf_size in the new APIs.
int32 Vgetnamelen(int32 vkey, uint16 name_len); / deprecated in 4.0 */
int32 Vgetclassnamelen(int32 vkey, uint16 classname_len); / deprecated in 4.0 */

bmribler and others added 2 commits June 10, 2026 10:47
The existing APIs Vgetname, Vgetclass, and Vinquire posed multiple
vulnerabilities due to the lack of size checks.  Because changing their
signature will break compatibilities, three new APIs are added in place
of their deprecation instead.  New APIs are:

int Vgetname40(int32 vkey, char *vgname, size_t *buf_size);
int Vgetclass40(int32 vkey, char *vgclass, size_t *buf_size);
int Vinquire40(int32 vkey, int32 *nentries, char *vgname, size_t *buf_size);

Fixes GH HDFGroup#872
@bmribler bmribler requested a review from ajelenak June 10, 2026 15:10
@bmribler bmribler added Component - C Library Core C library issues Type - Deprecation / Removal We strive for backward-compatibility, so it's worth noting this separately Type - New Feature Add a new API call, functionality, or tool Priority - 0. Blocker ⛔ This MUST be merged for the release to happen labels Jun 10, 2026
@bmribler bmribler added this to the 4.0 milestone Jun 10, 2026

@schwehr schwehr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick thoughts on the changes.

Edit: Thank you! These kinds of improvements are key for the long term stability of this old, but important, code base.

Comment thread hdf/src/hproto.h
HDFLIBAPI int32 Vgetnext(int32 vkey, int32 id);

HDFLIBAPI int32 Vgetname(int32 vkey, char *vgname);
HDFLIBAPI int Vgetname40(int32 vkey, char *vgname, size_t *buf_size); /* in 4.0 */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there 40 added to these function names? Maybe something in the name that implies it knows the string length?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention for 40 is they are introduced in 4.0. :D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm reconsidering this position...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have a clean break, no deprecated functions, cleaner API for 4.0

Comment thread hdf/src/hproto.h Outdated
HDFLIBAPI int Vinquire(int32 vkey, int32 *nentries, char *vgname);
HDFLIBAPI int32 Vgetnamelen(int32 vkey, uint16 *name_len); /* deprecated in 4.0 */

HDFLIBAPI int32 Vgetclassnamelen(int32 vkey, uint16 *classname_len); /* deprecated in 4.0 */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this also down below?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them. Thanks!!

Comment thread hdf/src/hproto.h Outdated
HDFLIBAPI int Vinquire(int32 vkey, int32 *nentries, char *vgname);
HDFLIBAPI int32 Vgetnamelen(int32 vkey, uint16 *name_len); /* deprecated in 4.0 */

HDFLIBAPI int32 Vgetclassnamelen(int32 vkey, uint16 *classname_len); /* deprecated in 4.0 */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider requiring the user to #define something to allow use of deprecated calls and default it to set in the CMake system?

@bmribler bmribler Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have plan to do much more in HDF4. 4.0 is very likely to be the last release. Applications can continue using 3.x if the user chooses to use deprecated APIs. Please see the note about deprecating.

Comment thread hdf/src/vgp.c
HGOTO_ERROR(DFE_ARGS, FAIL);

/* Get the vgroup struct for access */
if ((vg = VIGet_vgdesc(vkey)) == NULL)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching style how it checks against NULL. Above was if (NULL == . Use the same style across all.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer (... == NULL) but I'll use the existing style for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I suggest a follow up PR to switch to == NULL as I agree with your take on what is better these days.

Comment thread hdf/src/vgp.c
if (buf_size != NULL) {
if (vgname == NULL || *buf_size == 0) {
*buf_size = name_len; /* return the name length */
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return here so you don't have to indent for the else?

@bmribler bmribler marked this pull request as draft June 10, 2026 17:51
@bmribler

bmribler commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@schwehr Thank you for reviewing this PR! I'll close it but create another PR soon, and apply your comments there, where appropriate.

@bmribler bmribler closed this Jun 11, 2026
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 Priority - 0. Blocker ⛔ This MUST be merged for the release to happen Type - Deprecation / Removal We strive for backward-compatibility, so it's worth noting this separately Type - New Feature Add a new API call, functionality, or tool

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)

2 participants