GithubHelp home page GithubHelp logo

42_minishell's Introduction

Hi ๐Ÿ‘‹, I'm Marine

A computer programming student @42 from France, Paris

  • ๐ŸŒฑ Iโ€™m currently learning about cybersecurity
  • ๐Ÿ’ก My current side projects : my portfolio and a mental health tracker mobile app
  • ๐Ÿ“ซ How to reach me: [email protected]

Languages and Tools:

image image image image image image image image image image image image image image

ย marineks

42_minishell's People

Contributors

marineks avatar tmanolis avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

42_minishell's Issues

Env -i ./minishell

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

Tricky test in Builtin CD

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

SIGPIPE err - echo builtin

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

Parsing issues -> $?

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)

ENV not really updated

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)

SIGSEGV found in parse_heredoc (+ many still reachables)

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

Expander - Wrong output for variables that don't exist

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

Export builtin

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

Nb_pipes variable keeps stacking

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

Sort export + case of "export a" into "export"

Two issues with export :

  1. We should sort export in alphabetical order (when the command is export only)
  2. There is actually two differents t_env ! one for the export and one for env. As such, when doing export a nothing happens when displaying env. But if we do an export after, the a variable has been appended

Handle spaces

beware of this case:
bash-5.0$ ls | | |
which returns bash: syntax error near unexpected token |'`
and that we don't manage yet

Mixing redirections with Heredoc : error of priority

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

REDIRs out

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

env -i ./minishell

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

Echo builtin

Command : echo -nn

Difference in results:
Ours: -nn
Expected : behaves like the command echo -n, displaying the prompt without a newline.

Exiting the child process

We're not really exiting the child process after its execution, that's why we have to exit twice before truly exiting our program

Expander - Does not take into account brackets

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

Empty command line

There is a segfault when we press Enter without typing anything in after the prompt
we should protect the return of the readline function

Export builtin

Not the correct behaviour with the command export as a standalone
must implement

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.