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 cat << "$US"E"R" #314

Closed PaulicStudios closed 5 months ago

PaulicStudios commented 6 months ago
/workspaces/42-minishell ❯ cat << "$US"E"R"
Tokens:
Type: 0, Value: cat
Type: 15, Value:  
Type: 3, Value: <<
Type: 15, Value:  
Type: 11, Value: "
Type: 0, Value: $US
Type: 11, Value: "
Type: 0, Value: E
Type: 11, Value: "
Type: 0, Value: R
Type: 11, Value: "
Tokens:
Type: 0, Value: cat
Type: 15, Value:  
Type: 3, Value: <<
Type: 15, Value:  
Type: 11, Value: "
Type: 0, Value: 
Type: 11, Value: "
Type: 0, Value: E
Type: 11, Value: "
Type: 0, Value: R
Type: 11, Value: "
Tokens:
Type: 0, Value: cat
Type: 15, Value:  
Type: 3, Value: <<
Type: 15, Value:  
Type: 11, Value: "
Type: 0, Value: 
Type: 11, Value: "
Type: 0, Value: E
Type: 11, Value: "
Type: 0, Value: R
Type: 11, Value: "
=================================================================
==98711==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000009b50 at pc 0x563b262e14d1 bp 0x7fff67851f30 sp 0x7fff67851f28
READ of size 4 at 0x603000009b50 thread T0
    #0 0x563b262e14d0 in get_after_file src/input_parsing/rearrange_tokens.c:53
    #1 0x563b262e1cdc in rearrange_tokens src/input_parsing/rearrange_tokens.c:128
    #2 0x563b262d8882 in process_input src/prompt/prompt.c:23
    #3 0x563b262d8c56 in ft_execute_input src/prompt/prompt.c:51
    #4 0x563b262d8c56 in show_prompt src/prompt/prompt.c:91
    #5 0x563b262d6623 in main src/main.c:42
    #6 0x7f99af607d09 in __libc_start_main ../csu/libc-start.c:308
    #7 0x563b262d6359 in _start (/workspaces/42-minishell/minishell+0x4359)

0x603000009b50 is located 0 bytes inside of 32-byte region [0x603000009b50,0x603000009b70)
freed by thread T0 here:
    #0 0x7f99af8b8b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123
    #1 0x563b262e12a0 in get_file src/input_parsing/rearrange_tokens.c:43
    #2 0x563b262e8fbf  (/workspaces/42-minishell/minishell+0x16fbf)

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

SUMMARY: AddressSanitizer: heap-use-after-free src/input_parsing/rearrange_tokens.c:53 in get_after_file
Shadow bytes around the buggy address:
  0x0c067fff9310: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fa
  0x0c067fff9320: fa fa fd fd fd fa fa fa fd fd fd fd fa fa 00 00
  0x0c067fff9330: 00 07 fa fa fd fd fd fa fa fa fd fd fd fa fa fa
  0x0c067fff9340: fd fd fd fa fa fa 00 00 00 00 fa fa 00 00 00 00
  0x0c067fff9350: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa fd fd
=>0x0c067fff9360: fd fd fa fa 00 00 00 00 fa fa[fd]fd fd fd fa fa
  0x0c067fff9370: fd fd fd fd fa fa fd fd fd fd fa fa fd fd fd fd
  0x0c067fff9380: fa fa fd fd fd fd fa fa fd fd fd fa fa fa fd fd
  0x0c067fff9390: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa
  0x0c067fff93a0: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fa
  0x0c067fff93b0: fa fa fd fd fd fd fa fa fd fd fd fd fa fa fd fd
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
==98711==ABORTIN