GAS: Prevent dangling pointers in sframe_xlate_ctx_cleanup
GAS sframe context cleanup now explicitly nullifies pointers to prevent dangling pointers.
The sframe_xlate_ctx_cleanup function in the GNU Assembler (GAS) has been improved to prevent dangling pointers. After freeing memory associated with first_fre, remember_fre, and cur_fre, the function now explicitly sets these pointers to NULL. Additionally, related members like last_fre, num_xlate_fres, and flex_p are reset to their default states, ensuring a clean state after cleanup.
In Details
The sframe_xlate_ctx_cleanup function in gas/gen-sframe.c is responsible for freeing resources held by a sframe_xlate_ctx structure. Previously, while it freed the memory pointed to by first_fre, remember_fre, and cur_fre, it did not set these pointers to NULL. This commit adds explicit assignments to NULL for these pointers, as well as resetting last_fre, num_xlate_fres, and flex_p. This prevents potential use-after-free bugs if the context structure were re-used or inspected after cleanup.
- GAS
- The GNU Assembler, part of the GNU Binutils package, which translates assembly language code into machine code.
- sframe
- Stack Frame information, used by debugging tools to understand function call stacks. GAS uses sframe to generate DWARF unwind information.
- dangling pointer
- A pointer that no longer points to a valid memory location. This can occur after the memory it points to has been freed, leading to potential crashes or security vulnerabilities if accessed.