Commit graph

460 commits

Author SHA1 Message Date
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
920ad586e1 refactor(redirect): ambiguous redirect message to own file 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
5de82f2940 feat(debug): add function to easily treeprint a redirect 2025-04-21 11:00:14 +02:00
c00cc21ae4 feat(redirect): do variable expansion on redirect targets 2025-04-21 08:17:22 +02:00
2ae001e00b fix(exec/redirections): did not correctly restore fds when executing builtins
This caused redirections to keep stdout redirected to the outfile, which caused
problems with displaying the prmpt.

The shell hangs, but exits with C-d

Builtins affected:
echo hi > outfile
pwd > outfile
env > outfile
2025-04-18 14:14:43 +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
701174fc1b feat(debug): function to easily treeprint a worddesc 2025-04-18 09:20:49 +02:00
9271b7fa92 fix(parsing/pipeline): leak when optional pipeline returns NULL 2025-04-18 09:19:25 +02:00
6cc6e6cfb5 feat(debug): add function to easily treeprint a cmd 2025-04-17 12:28:57 +02:00
f1a0af09f8 feat(here_doc): handle signals (^C, ^\) correctly
This is a bit of a big commit, because I had to move some stuff to other files,
sorry about that. I can split it up if it's too big to review.
2025-04-17 12:06:48 +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
2ea4afda4a clean: move around some imports 2025-04-16 16:41:54 +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
d652f32cff feat(debug): a way to easily debug a wordlist 2025-04-16 15:30:18 +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
84a246f6f6 parsing: fix redir accepting operators as specifiers
before:
$ >>>>>
minishell: syntax error near unexpected token `newline'

after:
$ >>>>>
minishell: syntax error near unexpected token `>>'

>> is now correctly detected as an operator, and not a word
2025-04-16 13:59:14 +02:00
9593851149 parsing: show errors for unexpected newline
$ <
minishell: syntax error near unexpected token `newline'
$ >
minishell: syntax error near unexpected token `newline'
$ <<
minishell: syntax error near unexpected token `newline'
$ >>
minishell: syntax error near unexpected token `newline'
2025-04-16 13:16:34 +02:00
e1a1a43041 parsing: refactor cmds_parse into own file 2025-04-16 13:13:55 +02:00
73d691c0b4 parsing: refactor group_or_simple_parse into group_cmd_parse.c 2025-04-16 13:08:50 +02:00
a5103fa733 clean: remove unused paren files 2025-04-16 13:05:34 +02:00
dd30b44b93 parsing: refactor minishell_opt_cmds_parse into own file 2025-04-16 13:03:49 +02:00
ee5811ad63 ignore zms_tester 2025-04-16 12:48:23 +02:00
942217a45a tests: update tests to reflect new parser 2025-04-15 15:47:18 +02:00
81ba53237c parsing: do not reset last_return_value at start of parsing
we need to preserve it, to be able to show the return value from the last command
2025-04-15 15:45:29 +02:00
1a949bdcab minishell: reinstante interactive mode 2025-04-15 15:27:20 +02:00
0579d1f2fc
env: correctly handle write errors such as /dev/full
The exit status of 125 for env in case of failure is documented in env(1).
2025-04-15 15:19:27 +02:00
ffaf2582a3
pwd: correctly handle write errors 2025-04-15 15:19:27 +02:00
cfc95994de
echo: correctly handle write errors such as /dev/full 2025-04-15 15:19:27 +02:00
871180f6d8
connec_pipe_cmd_execute: setup pipes between commands 2025-04-15 15:19:27 +02:00
81febcfcdd
debug: show command about to be executed in debug mode 2025-04-15 15:19:27 +02:00
204ed35ff4
fix(connec_cmd_execute): do not execute more than one command per process 2025-04-15 15:17:52 +02:00
596b21fc2f
debug, destroy all new types (also some code for testing it) 2025-04-15 15:17:51 +02:00
82da182773
fix: potential buffer overflow caused by missing terminating null byte in t_buffer
This only occurs in specific circumstances where the number of bytes to be added
to a t_buffer via the ft_buffer_push_buf function is exactly equal to the number
of free bytes in the current underlying buffer. This does not occur if the
number of bytes to add to the buffer is smaller than that, since we allocate new
space using ft_calloc.

In these circumstances, since no terminating null byte is added, other code may
read past the end of the buffer, causing a buffer overflow.
2025-04-15 15:17:51 +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
6576c47b56
exec: command to toggle execution
Execution starts out being enabled. But it can be toggled on and off by using
the .exec command.
2025-04-15 15:17:51 +02:00