Prompt : Create your own shell
marineks / 42_minishell Goto Github PK
View Code? Open in Web Editor NEWPrompt : Create your own shell
Prompt : Create your own shell
We must protect our fds in the case of :
CMD WORD > FILE1 > FILE2 > FILE3
=> file1 and file2 will be erased and WORD will only be written in FILE3
=> we must close the previous fd beforehand
When trying the command export
as a standalone there is a segfault
I think it's because we loop through cmd->infos.flags[i] without checking first if there is a cmd->infos.flags
There is a segfault when we press Enter without typing anything in after the prompt
we should protect the return of the readline function
Expected behaviour
bash-5.0$ echo $=HOME
$=HOME
vs ours:
echo
It seems this character is also a delimiter when a dollar sign precedes it
The count is correct in function find_pipes
However, from a command entered by a user to another, the previous count is added to the current one
=> to be reset
Command : echo -nn
Difference in results:
Ours: -nn
Expected : behaves like the command echo -n
, displaying the prompt without a newline.
Diff of outputs with the command echo $?test
:
Ours : prints nothing (likely because it does not find the var ?test
in env)
Expected : 0test
(expands $?
and prints test
just after)
export test=".."
cd $test
Expected behaviour : expansion of $test variable and the final cmd => cd ..
Instead, even if data->env_copy is updated, the expander part only takes into account the first copy of envp (char **envp) and not the updated version (data->env_copy)
Expected behaviour of bash --posix :
cat <dontexist << EOF
returns:
> test
> EOF
bash: dontexist: No such file or directory
Whereas ours returns the error message of the redirection first :
bash: dontexist: No such file or directory
> test
> EOF
When we exit directly in the heredoc by entering the delimiter, there are several leaks:
Test case :
๐ฆ๐ ~ Minishell : cat << lol
> lol
Results from valgrind :
==37046== Invalid read of size 1
==37046== at 0x408109: ft_strjoin (in /mnt/nfs/homes/msanjuan/Documents/Projets_Github/42_Minishell/minishell)
==37046== by 0x403EF1: get_line_in_submode (03_parse_heredoc.c:39)
==37046== by 0x403DF0: stock_buffer (03_parse_heredoc.c:54)
==37046== by 0x403CC8: parse_heredoc (03_parse_heredoc.c:87)
==37046== by 0x403120: create_cmds (00_create_cmds.c:33)
==37046== by 0x401438: main (main.c:45)
==37046== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==37046==
==37046==
==37046== Process terminating with default action of signal 11 (SIGSEGV)
==37046== Access not within mapped region at address 0x0
==37046== at 0x408109: ft_strjoin (in /mnt/nfs/homes/msanjuan/Documents/Projets_Github/42_Minishell/minishell)
==37046== by 0x403EF1: get_line_in_submode (03_parse_heredoc.c:39)
==37046== by 0x403DF0: stock_buffer (03_parse_heredoc.c:54)
==37046== by 0x403CC8: parse_heredoc (03_parse_heredoc.c:87)
==37046== by 0x403120: create_cmds (00_create_cmds.c:33)
==37046== by 0x401438: main (main.c:45)
==37046== If you believe this happened as a result of a stack
==37046== overflow in your program's main thread (unlikely but
==37046== possible), you can try to increase the size of the
==37046== main thread stack using the --main-stacksize= flag.
==37046== The main thread stack size used in this run was 8388608.
==37046==
==37046== FILE DESCRIPTORS: 4 open at exit.
==37046== Open file descriptor 4:
==37046== at 0x49C295B: pipe (syscall-template.S:78)
==37046== by 0x403C07: parse_heredoc (03_parse_heredoc.c:68)
==37046== by 0x403120: create_cmds (00_create_cmds.c:33)
==37046== by 0x401438: main (main.c:45)
==37046==
==37046== Open file descriptor 2: /dev/pts/2
==37046== <inherited from parent>
==37046==
==37046== Open file descriptor 1: /dev/pts/2
==37046== <inherited from parent>
==37046==
==37046== Open file descriptor 0: /dev/pts/2
==37046== <inherited from parent>
==37046==
==37046==
==37046== HEAP SUMMARY:
==37046== in use at exit: 251,437 bytes in 1,310 blocks
==37046== total heap usage: 1,568 allocs, 258 frees, 273,090 bytes allocated
Most likely need to check and add protections in ft_strjoin
In the following examples, the syntax error output is not triggered:
Must complete "check_consecutive_ops" function
Problem with cmd word > file word
The second word is identified as a cmd and not a word => pb w/ pointers I think
Test case :
๐ฆ๐ ~ Minishell : foo bar baz | echo -nnn bonjour | pwd
foo: command not found
/mnt/nfs/homes/msanjuan/Documents/Projets_Github/42_Minishell
==77643==
==77643== Process terminating with default action of signal 13 (SIGPIPE)
==77643== at 0x49C20A7: write (write.c:26)
==77643== by 0x404798: get_echo (00_echo.c:102)
==77643== by 0x4059C4: exec_one_builtin (exec_builtin.c:30)
==77643== by 0x405B08: exec_builtin_with_pipe (exec_builtin.c:51)
==77643== by 0x405BCE: child_process (exec_processes.c:76)
==77643== by 0x406161: exec_cmd (exec.c:74)
==77643== by 0x40622B: exec (exec.c:98)
==77643== by 0x40143C: main (main.c:48)
==77642==
==77642== FILE DESCRIPTORS: 3 open at exit.
==77642== Open file descriptor 2: /dev/pts/1
==77642== <inherited from parent>
==77642==
==77642== Open file descriptor 1: /dev/pts/1
==77642== <inherited from parent>
==77642==
==77642== Open file descriptor 0: /dev/pts/1
==77642== <inherited from parent>
==77642==
==77642==
==77642== HEAP SUMMARY:
==77642== in use at exit: 204,668 bytes in 215 blocks
==77642== total heap usage: 1,084 allocs, 869 frees, 252,628 bytes allocated
==77642==
==77642== LEAK SUMMARY:
==77642== definitely lost: 0 bytes in 0 blocks
==77642== indirectly lost: 0 bytes in 0 blocks
==77642== possibly lost: 0 bytes in 0 blocks
==77642== still reachable: 0 bytes in 0 blocks
==77642== suppressed: 204,668 bytes in 215 blocks
==77642==
==77642== For lists of detected and suppressed errors, rerun with: -s
==77642== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Occurs as well in these cases:
๐ฆ๐ ~ Minishell : foo bar baz | env | pwd
๐ฆ๐ ~ Minishell : echo -nnn bonjour | foo bar | pwd
Does not occur with theses commands :
๐ฆ๐ ~ Minishell : foo bar baz | echo -nnn | pwd
๐ฆ๐ ~ Minishell : foo bar baz | ls | pwd
๐ฆ๐ ~ Minishell : foo bar baz | cat Makefile | pwd
๐ฆ๐ ~ Minishell : foo bar baz | pwd | pwd
๐ฆ๐ ~ Minishell : pwd | foo bar | echo -nnn bonjour
Not the correct behaviour with the command export
as a standalone
must implement
When someone erase the env before launching our executable, we segfault automatically
Bash --posix's correct behaviour :
PWD=/mnt/nfs/homes/msanjuan/Documents/Projets_Github/42_Minishell
SHLVL=1
_=/usr/bin/env
In any case, we should not crash, so returning an error when !envp
should be considered enough
We're not really exiting the child process after its execution, that's why we have to exit twice before truly exiting our program
Two issues with export :
export
only)export a
nothing happens when displaying env
. But if we do an export
after, the a
variable has been appendedCommand : export test=$?ok
Expected behaviour : test=0ok
Our minishell : test=$?ok
Example:
bash-5.0$ echo my terminal is [$TERM]
my terminal is [xterm-256color]
Whereas ours searches for the variables $TERM] and returns:
my terminal is [
=> Conclusion: the brackets should be considered as a delimiter
beware of this case:
bash-5.0$ ls | | |
which returns bash: syntax error near unexpected token
|'`
and that we don't manage yet
Example:
`bash-5.0$ echo $IDONTEXIST
`
Whereas ours returns:
(null)
I think the problem comes from our split_var function, line30 :
ft_lstadd_back_token(&tk_lst, ft_lstnew_token(NULL, VAR, DEFAULT));
To be checked
We prevent our program from crashing when all the envp is unset but it would be better suited to add the basic env variables as bash --posix does :
PWD=/mnt/nfs/homes/msanjuan/Documents/Projets_Github/42_Minishell
SHLVL=1
_=/usr/bin/env
Test :
bash-5.0$ mkdir test
bash-5.0$ cd test
bash-5.0$ ls
bash-5.0$ rm -r ../test
Expected behaviour :
bash-5.0$ cd ../
bash: cd: ../: No such file or directory
bash-5.0$ ls
ls: cannot open directory '.': Stale file handle
Whereas ours results in :
๐ฆ๐ ~ Minishell : cd ../
๐ฆ๐ ~ Minishell : ls
ignorereadline Makefile README.md tests.txt
incl minishell srcs test.txt
libft objs tester.sh
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.