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

debug ctx_Type_GetName does not take trailing NULL into account #448

Closed
mattip opened this issue Sep 14, 2023 · 2 comments · Fixed by #449
Closed

debug ctx_Type_GetName does not take trailing NULL into account #448

mattip opened this issue Sep 14, 2023 · 2 comments · Fixed by #449
Assignees
Labels
bug Something isn't working HPy update in GraalPy This change requires a related change in GraalPy HPy update in PyPy This change requires a related change in PyPy
Milestone

Comments

@mattip
Copy link
Contributor

mattip commented Sep 14, 2023

In this call the trailing NULL is not copied back out of protect_and_associate_data_ptr, so I am getting garbage on the end of the returned char*. I think n_name should be incremented to include the trailing NULL.

ctx_info->is_valid = false;
const char *name = HPyType_GetName(uctx, uh_type);
ctx_info->is_valid = true;
n_name = strlen(name);
return (const char *)protect_and_associate_data_ptr(type, (void *)name, n_name);
}

@mattip
Copy link
Contributor Author

mattip commented Sep 14, 2023

I put this fix into PyPy:

# HG changeset patch
# User Matti Picus <[email protected]>
# Date 1694719428 -10800
#      Thu Sep 14 22:23:48 2023 +0300
# Branch hpy-0.9
# Node ID d1d83b7bc8d3e18708d15c4dfbc802cd3a640552
# Parent  93f6b1f6f9d6fe6cfa837b231e61fc70c66218c5
Fix for upstream issue 448: copy out trailing NULL

diff -r 93f6b1f6f9d6 -r d1d83b7bc8d3 pypy/module/_hpy_universal/_vendored/hpy/debug/src/debug_ctx.c
--- a/pypy/module/_hpy_universal/_vendored/hpy/debug/src/debug_ctx.c	Thu Sep 14 22:23:09 2023 +0300
+++ b/pypy/module/_hpy_universal/_vendored/hpy/debug/src/debug_ctx.c	Thu Sep 14 22:23:48 2023 +0300
@@ -559,7 +559,7 @@
     ctx_info->is_valid = false;
     const char *name = HPyType_GetName(uctx, uh_type);
     ctx_info->is_valid = true;
-    n_name = strlen(name);
+    n_name = strlen(name) + 1;
     return (const char *)protect_and_associate_data_ptr(type, (void *)name, n_name);
 }

@fangerer
Copy link
Contributor

Thanks for the catch. I'll include it in the final 0.9.0 release.

@fangerer fangerer added this to the ABI version 1 milestone Sep 15, 2023
@fangerer fangerer self-assigned this Sep 15, 2023
@fangerer fangerer added bug Something isn't working HPy update in PyPy This change requires a related change in PyPy HPy update in GraalPy This change requires a related change in GraalPy labels Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working HPy update in GraalPy This change requires a related change in GraalPy HPy update in PyPy This change requires a related change in PyPy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants