Fix dangling suffix pointer in tracked library info#175
Draft
ViralBShah wants to merge 1 commit into
Draft
Conversation
`record_library_load()` stored the autodetected `suffix` pointer directly, unlike `libname` which is deep-copied. This is only safe when `suffix` is a static string literal, but `autodetect_symbol_suffix()` checks the caller-supplied `suffix_hint` first and returns that pointer when it matches. In the `LBT_DEFAULT_LIBS` path that hint is a stack buffer in `init()`, so `lbt_config.loaded_libs[i]->suffix` would dangle after `init()` returns and a later `lbt_get_config()` read would be a use-after-return (triggered by e.g. `LBT_DEFAULT_LIBS="libopenblas64.so!64_"`). Deep-copy the suffix in `record_library_load()` and free it in `clear_loaded_libraries()`, matching the existing handling of `libname`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
record_library_load()insrc/config.cstored the autodetectedsuffixpointer directly, unlikelibnamewhich is deep-copied:This is safe only if
suffixis always a static string literal. Butautodetect_symbol_suffix()checks the caller-suppliedsuffix_hintfirst and returns that pointer when it matches. In theLBT_DEFAULT_LIBScode path that hint is a stack buffer ininit(), solbt_config.loaded_libs[i]->suffixdangles onceinit()returns — a laterlbt_get_config()read of.suffixis a use-after-return.Reproducible with e.g.
LBT_DEFAULT_LIBS="libopenblas64.so!64_".Fix
Deep-copy the suffix in
record_library_load()and free it inclear_loaded_libraries(), mirroring the existinglibnamehandling.Notes