JonasGoetz01 / 42-minishell

Built your very own shell, Minishell! Explore executing commands, managing history, and controlling inputs and outputs. Dive into handling processes and files while creating a user-friendly shell interface. Get hands-on with shell scripting in a fun and accessible way with Minishell (DONT PANIC SHELL)!
1 stars 1 forks source link

<< "" segfault #326

Closed PaulicStudios closed 5 months ago

PaulicStudios commented 6 months ago
/workspaces/42-minishell ❯ << ""
=================================================================
==13260==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000002ad0 at pc 0x5607526b497e bp 0x7ffe768c5bc0 sp 0x7ffe768c5bb8
READ of size 4 at 0x604000002ad0 thread T0
    #0 0x5607526b497d in get_after_file src/input_parsing/rearrange_tokens.c:55
    #1 0x5607526b5194 in rearrange_tokens src/input_parsing/rearrange_tokens.c:144
    #2 0x5607526ab7bb in process_input src/prompt/prompt.c:35
    #3 0x5607526abb92 in ft_execute_input src/prompt/prompt.c:63
    #4 0x5607526abb92 in show_prompt src/prompt/prompt.c:103
    #5 0x5607526a9623 in main src/main.c:42
    #6 0x7f75302a2d09 in __libc_start_main ../csu/libc-start.c:308
    #7 0x5607526a9359 in _start (/workspaces/42-minishell/minishell+0x4359)

0x604000002ad0 is located 0 bytes inside of 40-byte region [0x604000002ad0,0x604000002af8)
freed by thread T0 here:
    #0 0x7f7530553b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123
    #1 0x5607526b4637 in get_file src/input_parsing/rearrange_tokens.c:43
    #2 0x60700000200f  (<unknown module>)

previously allocated by thread T0 here:
    #0 0x7f7530553e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x5607526af0c6 in create_token src/input_parsing/token_utils.c:32

SUMMARY: AddressSanitizer: heap-use-after-free src/input_parsing/rearrange_tokens.c:55 in get_after_file
Shadow bytes around the buggy address:
  0x0c087fff8500: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd fa
  0x0c087fff8510: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fd
  0x0c087fff8520: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x0c087fff8530: fa fa fd fd fd fd fd fd fa fa 00 00 00 00 00 fa
  0x0c087fff8540: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd fa
=>0x0c087fff8550: fa fa 00 00 00 00 00 fa fa fa[fd]fd fd fd fd fa
  0x0c087fff8560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff8570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff8580: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff8590: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff85a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==13260==ABORTING
PaulicStudios commented 6 months ago

should be a valid input