Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AddressSanitizer issue in cache test #5235

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

jhendersonHDF
Copy link
Collaborator

@jhendersonHDF jhendersonHDF commented Jan 14, 2025

Fixes issues with usages of stack variables after function return related to API context pushing/popping

@jhendersonHDF jhendersonHDF added Priority - 2. Medium ⏹ It would be nice to have this in the next release Component - Testing Code in test or testpar directories, GitHub workflows Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub labels Jan 14, 2025
@jhendersonHDF jhendersonHDF marked this pull request as draft January 14, 2025 19:29
@jhendersonHDF jhendersonHDF marked this pull request as ready for review January 14, 2025 22:03
@jhendersonHDF
Copy link
Collaborator Author

Reworked this a little bit to handle the other stack issues as well

Fix usages of stack variables after function return by
removing extraneous H5CX_push/pop operations and hoisting
a stack variable to a higher scope

if (show_progress) /* 3 */
fprintf(stdout, "%s() - %0d -- pass = %d\n", __func__, mile_stone++, (int)pass);

/* Push API context */
H5CX_push(&api_ctx);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All of the push/pop calls in these tests appear to have been unnecessary, as API contexts are all pushed right after setup_cache() (which pushes its own API context) and popped right after takedown_cache() (which pops its own API context), at least before the initial version of this fix. Just removed all the extra push/pop calls and kept the single context pushed/popped by the setup/takedown functions.

haddr_t actual_base_addr;
hid_t fapl_id = H5P_DEFAULT;
hid_t fcpl_id = H5P_DEFAULT;
H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As H5CX_push() has since been refactored to use the passed in context object directly, rather then allocating a new node, this variable needs to be hoisted out of this function. Otherwise, the library will be holding onto a stale address once this function returns. The simplest way seemed to be just to pass in a pointer to a H5CX_node_t, but, again, this seems to point to design issues.

@@ -26856,20 +26577,16 @@ check_flush_deps_err(unsigned paged)
} /* end switch */

takedown_cache(file_ptr, false, false);
if (!pass)
if (!pass) {
file_ptr = NULL;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Prevent accidentally calling takedown_cache() twice in case the first time fails

Copy link
Contributor

@qkoziol qkoziol left a comment

Choose a reason for hiding this comment

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

Good change! 👍

@lrknox lrknox merged commit c83ca7d into HDFGroup:develop Jan 15, 2025
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Testing Code in test or testpar directories, GitHub workflows Priority - 2. Medium ⏹ It would be nice to have this in the next release Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants