hstr icon indicating copy to clipboard operation
hstr copied to clipboard

Uninitialized read in favorites_add()

Open juppytt opened this issue 1 year ago • 1 comments

  1. Launch hstr with favorites view `./src/hstr -f'. Both history and favorites files (~/.zsh_history and ~/.hstr_favorites) are empty.
  2. Search a string (e.g., 'AAA`)
  3. Switch to the ranking view (Ctrl-Slash)
  4. Reach the prompt bottom (Ctrl-J) and add it to the favorites (Ctrl-F)
  5. Crashes with invalid read. hstr->selection is allocated but not initialized.

https://github.com/dvorka/hstr/blob/be59f8cf5a48af43a66963c8220b888563aeea0c/src/hstr.c#L1210-L1217 https://github.com/dvorka/hstr/blob/be59f8cf5a48af43a66963c8220b888563aeea0c/src/hstr.c#L1395-L1402

Stopped reason: SIGSEGV
0x00007ffff7ce8717 in ?? () from /usr/lib/x86_64-linux-gnu/libc.so.6
gdb-peda$ bt
#0  0x00007ffff7ce8717 in ?? () from /usr/lib/x86_64-linux-gnu/libc.so.6
#1  0x00005555555cb10d in __interceptor_strlen (
    s=0xbebebebebebebebe <error: Cannot access memory at address 0xbebebebebebebebe>)
    at /home/juhee/project/foxfuzz/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:459
#2  0x000055555566f30d in hstr_strdup (
    s=0xbebebebebebebea0 <error: Cannot access memory at address 0xbebebebebebebea0>, 
    s@entry=0xbebebebebebebebe <error: Cannot access memory at address 0xbebebebebebebebe>)
    at hstr_utils.c:34
#3  0x000055555567156f in favorites_add (favorites=0x603000000070, 
    newFavorite=0xbebebebebebebebe <error: Cannot access memory at address 0xbebebebebebebebe>)
    at hstr_favorites.c:149
#4  0x000055555567be90 in loop_to_select () at hstr.c:1401
#5  0x000055555567d6fa in hstr_interactive () at hstr.c:1660
#6  0x000055555567dcce in hstr_main (argc=0x2, argv=0x7fffffffe058) at hstr.c:1744
#7  0x00007ffff7b84083 in __libc_start_main () from /usr/lib/x86_64-linux-gnu/libc.so.6
#8  0x000055555557559e in _start ()
gdb-peda$ 

juppytt avatar Dec 05 '22 08:12 juppytt