Commit graph

62 commits

Author SHA1 Message Date
aca85c3583 fix(expansion/redirection): prevent infinite loop of redir list pointing to itself
also add a hard limit of OVER 9000! iterations for the problematic loop
2025-04-24 12:45:00 +02:00
bf26afce2b fix(debug): correctly print here_doc_eof in redirect debug 2025-04-24 12:45:00 +02:00
38ffac7fc3 feat(redir): expand wildcards in targets and handle ambiguous redirects 2025-04-24 12:45:00 +02:00
2dd20b21bc feat(redir): fieldsplit redir target, and handle ambiguous redirects 2025-04-24 12:44:33 +02:00
c00cc21ae4 feat(redirect): do variable expansion on redirect targets 2025-04-21 08:17:22 +02:00
1499eaa985 test(builtin/export): ensure that variable substitution happens correctly 2025-04-18 10:37:49 +02:00
5fabec58d5 test(builtin/export): ensure that identifiers are correctly accepted or rejected 2025-04-18 10:30:21 +02:00
c5e15903e0 fix(builtin/export): show error on invalid identifiers such as % and $ 2025-04-18 10:17:21 +02:00
efaf4708f9 fix(builtin/export): empty arguments were not identified as invalid identifiers 2025-04-18 10:03:09 +02:00
6b2e15d301 test: migrate some tests from zms_testeur 2025-04-18 09:57:41 +02:00
d44691a5b0 fix(exec): running a command with an absolute path which does not exist now gives correct error
Before, it gave "Is a directory" error, but now it correctly gives "No such file
or directory".
2025-04-18 09:25:11 +02:00
655ff36351 fix(susbt/variable): empty variables on their own are removed 2025-04-18 09:22:18 +02:00
9271b7fa92 fix(parsing/pipeline): leak when optional pipeline returns NULL 2025-04-18 09:19:25 +02:00
5e6d7b3b4e fix(parsing/here_doc): segfault & invalid fd & premature exit 2025-04-17 11:25:59 +02:00
3be2969946 fix(parsing/simple_cmd): leak when invalid redirection after word in simple_cmd 2025-04-16 18:21:33 +02:00
49a897b44e subst/variable: remove special handling of positional variables
Including only half support does not make sense, it could cause more problems
than it solves.
2025-04-16 18:05:11 +02:00
d53e40d3f4 fix(subst/variable): invalid identifiers were having their $ swallowed
It is safe to delete this part:
```c
if (!rep)
   return (NULL);
```
because rep is always returned, and no other code depends on that value
2025-04-16 17:50:23 +02:00
733ae1093a fix(exec): correctly exit subprocesses, do not keep multiple shells in parallel 2025-04-16 17:30:25 +02:00
96e46e9130 fix(parsing/cmdgroup): report error the same way as everywhere else, prevent double report
before:
```
$ ()
minishell: syntax error near unexpected token `)'
minishell: syntax error near unexpected token `)'
```
after:
```
$ ()
minishell: syntax error near unexpected token `)'
```
This probably fixes a few bugs as well, but I didn't look too hard. It just
seemed nicer to have a consistent way to report errors.
2025-04-16 15:52:22 +02:00
ced979dd31 fix(parsing/simple_cmd): report error the same way as everywhere else, prevent leak 2025-04-16 15:38:51 +02:00
18225f3356 fix(executing): return code on unknown cmd was unchanged, is now set to 127 2025-04-16 15:00:20 +02:00
9a32220945 redir_parsing: fix memory leak when parsing a redirection with an operator as specifier
if the specifier was not WORD_TOKEN, the operator was not being freed
2025-04-16 14:13:01 +02:00
942217a45a tests: update tests to reflect new parser 2025-04-15 15:47:18 +02:00
81febcfcdd
debug: show command about to be executed in debug mode 2025-04-15 15:19:27 +02:00
3ec90f7770
token_type: assign token_type to worddesc during wordsplit
Also added some tests for that part.
2025-04-15 15:17:51 +02:00
4d6a64bf6a
debug: worddesc show more information
This seems appropriate since worddescs are getting more and more complex:
markers, flags, tokentypes, ...
2025-04-15 15:17:51 +02:00
386d2bcb3a
exec: correct error and return value when cmd is a directory
minishell: /: Is a directory
$? = 126
2025-04-15 15:11:50 +02:00
d08c9a6727
tests: check simple noops 2025-04-15 15:11:50 +02:00
be183b99ee
minishell: do wildcard expansion 2025-04-15 15:06:46 +02:00
32e3976774
field splitting: implement field splitting 2025-04-15 15:05:52 +02:00
0cfa2677c5
fix(echo): echo - was treated as echo -n
Small logic error on my part
2025-04-15 15:03:13 +02:00
d40560bb37
unset: implement unset 2025-04-15 15:03:13 +02:00
1ef8b7a0ae
env: implement builtin env 2025-04-15 15:03:13 +02:00
0de583cf45
echo: implement builtin echo 2025-04-15 15:03:13 +02:00
715c2aced8
exit: handle invalid and large arguments 2025-04-15 15:03:13 +02:00
f1c132337b
exit: work for simple arguments
This does not address non-integer arguments, or extremly high/low arguments.
2025-04-15 15:03:13 +02:00
24ba87abba
exec: retain exit status of commands, including if they were signaled 2025-04-15 15:01:19 +02:00
0842fdfe1d
fix: double free when getting command path for empty command
```
minishell$ ""
```
leads to the following error:
```
=================================================================
==1158770==ERROR: AddressSanitizer: attempting double-free on 0x5060000020c0 in thread T0:
    #0 0x5649fcb5b8a8 in free.part.0 asan_malloc_linux.cpp.o
    #1 0x5649fcbac549 in deal_with_filled_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:119:3
    #2 0x5649fcbac38b in filepath_from_env /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:165:10
    #3 0x5649fcbac220 in get_cmdpath /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:186:10
    #4 0x5649fcba8664 in simple_cmd_execute /home/khais/src/42/common_env/minishell/src/executing/simple_cmd/simple_cmd_execute.c:71:8
    #5 0x5649fcba6e4c in execute_command /home/khais/src/42/common_env/minishell/src/minishell.c:49:2
    #6 0x5649fcba6ce5 in main /home/khais/src/42/common_env/minishell/src/minishell.c:92:3
    #7 0x7fb4f2dcd27d in __libc_start_call_main (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a27d) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)
    #8 0x7fb4f2dcd338 in __libc_start_main@GLIBC_2.2.5 (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a338) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)
    #9 0x5649fca6f394 in _start (/home/khais/src/42/common_env/minishell/minishell+0x2b394)

0x5060000020c0 is located 0 bytes inside of 58-byte region [0x5060000020c0,0x5060000020fa)
freed by thread T0 here:
    #0 0x5649fcb5b8a8 in free.part.0 asan_malloc_linux.cpp.o
    #1 0x5649fcbac669 in select_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:81:3
    #2 0x5649fcbac524 in deal_with_filled_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:116:9
    #3 0x5649fcbac38b in filepath_from_env /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:165:10
    #4 0x5649fcbac220 in get_cmdpath /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:186:10
    #5 0x5649fcba8664 in simple_cmd_execute /home/khais/src/42/common_env/minishell/src/executing/simple_cmd/simple_cmd_execute.c:71:8
    #6 0x5649fcba6e4c in execute_command /home/khais/src/42/common_env/minishell/src/minishell.c:49:2
    #7 0x5649fcba6ce5 in main /home/khais/src/42/common_env/minishell/src/minishell.c:92:3
    #8 0x7fb4f2dcd27d in __libc_start_call_main (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a27d) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)

previously allocated by thread T0 here:
    #0 0x5649fcb5c897 in malloc (/home/khais/src/42/common_env/minishell/minishell+0x118897)
    #1 0x5649fcbac6be in alloc_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp_utils.c:34:9
    #2 0x5649fcbac4e9 in deal_with_filled_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:113:15
    #3 0x5649fcbac38b in filepath_from_env /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:165:10
    #4 0x5649fcbac220 in get_cmdpath /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:186:10
    #5 0x5649fcba8664 in simple_cmd_execute /home/khais/src/42/common_env/minishell/src/executing/simple_cmd/simple_cmd_execute.c:71:8
    #6 0x5649fcba6e4c in execute_command /home/khais/src/42/common_env/minishell/src/minishell.c:49:2
    #7 0x5649fcba6ce5 in main /home/khais/src/42/common_env/minishell/src/minishell.c:92:3
    #8 0x7fb4f2dcd27d in __libc_start_call_main (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a27d) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)

SUMMARY: AddressSanitizer: double-free asan_malloc_linux.cpp.o in free.part.0
==1158770==ABORTING
```

Looks like select_path frees filepath sometimes, no idea why. Removing these
lines didn't break any tests.

I'm pushing this to get a second opinion
2025-04-15 14:41:44 +02:00
ba4192bf8d
export: set correct exit status 2025-04-01 15:58:56 +02:00
3cdf7c3f76
export: handle invalid identifiers 2025-04-01 15:54:46 +02:00
299e016a27
export: handle simple cases 2025-04-01 14:39:02 +02:00
b92aa33c4e
inttests: fix test runner sometimes reporting wrong todo count 2025-04-01 14:28:47 +02:00
bac3512898
minishell: do variable substitution in postprocessing 2025-04-01 13:50:14 +02:00
7153df9305
cd: print error if cd is called with too many arguments 2025-03-31 20:06:34 +02:00
a66b71e5ce
cd: ensure relative paths work as expected 2025-03-31 19:59:32 +02:00
f1b2e1e22d
cd: handle empty argument 2025-03-31 17:07:46 +02:00
8f3c15f096
cd: when going to $HOME, show error message if it is unset 2025-03-31 16:58:21 +02:00
e046d151a2
inttests: add ability to manipulate environment for a single test 2025-03-31 16:57:40 +02:00
d66ca10a0c
cd: with no arg, go to $HOME 2025-03-31 16:40:22 +02:00
e93e6efb93
builtins: cd: implement cd to absolute paths 2025-03-31 16:34:48 +02:00