Skip to content

Commit

Permalink
[cpp] Check errors from execve (#1212)
Browse files Browse the repository at this point in the history
Related to #1213.
  • Loading branch information
scallyw4g committed Jul 6, 2022
1 parent 099cba5 commit 4c35031
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions cpp/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ inline mylib::LineReader* fdopen(int fd, Str* c_mode) {
return new mylib::CFileLineReader(f);
}

// Dummy exception posix::error
class error {};

inline void execve(Str* argv0, List<Str*>* argv, Dict<Str*, Str*>* environ) {
mylib::Str0 _argv0(argv0);

Expand All @@ -132,11 +135,18 @@ inline void execve(Str* argv0, List<Str*>* argv, Dict<Str*, Str*>* environ) {
}
_argv[n] = nullptr;

::execve(_argv0.Get(), _argv, nullptr);
int ret = ::execve(_argv0.Get(), _argv, nullptr);
if (ret == -1)
{
throw IOError(errno);
}

// NOTE(Jesse): ::execve() is specified to never return on success. If we
// hit this assertion, it returned successfully (or at least something other
// than -1) but should have overwritten our address space with the invoked process'
InvalidCodePath();
}

// Dummy exception posix::error
class error {};

} // namespace posix

Expand Down
4 changes: 0 additions & 4 deletions test/baseline.spec-cpp.assertion_fails
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
(_build/cpp/osh_eval.cc:8810: virtual int executor::ShellExecutor::RunSimpleCommand(runtime_asdl::cmd_value__Argv*, runtime_asdl::CommandStatus*, bool, bool): Assertion `0' failed.) _tmp/spec/cpp/command_.html
(_build/cpp/osh_eval.cc:8810: virtual int executor::ShellExecutor::RunSimpleCommand(runtime_asdl::cmd_value__Argv*, runtime_asdl::CommandStatus*, bool, bool): Assertion `0' failed.) _tmp/spec/cpp/command_.html
(_build/cpp/osh_eval.cc:8810: virtual int executor::ShellExecutor::RunSimpleCommand(runtime_asdl::cmd_value__Argv*, runtime_asdl::CommandStatus*, bool, bool): Assertion `0' failed.) _tmp/spec/cpp/toysh-posix.html
(cpp/pgen2_parse.cc:8: void parse::Parser::setup(int): Assertion `0' failed.) _tmp/spec/cpp/arith-context.html
(cpp/pgen2_parse.cc:8: void parse::Parser::setup(int): Assertion `0' failed.) _tmp/spec/cpp/bugs.html
(cpp/pgen2_parse.cc:8: void parse::Parser::setup(int): Assertion `0' failed.) _tmp/spec/cpp/bugs.html
(cpp/pgen2_parse.cc:8: void parse::Parser::setup(int): Assertion `0' failed.) _tmp/spec/cpp/errexit-oil.html
(/home/scallywag/work/oil/cpp/core_pyos.h:122: bool pyos::InputAvailable(int): Assertion `0' failed.) _tmp/spec/cpp/builtin-io.html
(/home/scallywag/work/oil/mycpp/gc_heap.h:268: void gc_heap::Heap::PushRoot(gc_heap::Obj**): Assertion `roots_top_ &lt; kMaxRoots' failed.) _tmp/spec/cpp/alias.html
(/home/scallywag/work/oil/mycpp/gc_heap.h:268: void gc_heap::Heap::PushRoot(gc_heap::Obj**): Assertion `roots_top_ &lt; kMaxRoots' failed.) _tmp/spec/cpp/ble-idioms.html
IF YOU SEE THIS OSH IS CRASHING (_tmp/spec/cpp/for-expr.html:<pre>OSH_CPP_SEGFAULT)
4 changes: 4 additions & 0 deletions test/baseline.spec-cpp.results
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@
35 _tmp/spec/cpp/builtin-printf.tsv
38 _tmp/spec/cpp/builtin-printf.tsv
39 _tmp/spec/cpp/builtin-printf.tsv
44 _tmp/spec/cpp/builtin-printf.tsv
45 _tmp/spec/cpp/builtin-printf.tsv
46 _tmp/spec/cpp/builtin-printf.tsv
47 _tmp/spec/cpp/builtin-printf.tsv
Expand Down Expand Up @@ -808,6 +809,7 @@
1 _tmp/spec/cpp/exit-status.tsv
2 _tmp/spec/cpp/exit-status.tsv
3 _tmp/spec/cpp/exit-status.tsv
4 _tmp/spec/cpp/exit-status.tsv
5 _tmp/spec/cpp/exit-status.tsv
6 _tmp/spec/cpp/exit-status.tsv
7 _tmp/spec/cpp/exit-status.tsv
Expand Down Expand Up @@ -863,6 +865,7 @@
4 _tmp/spec/cpp/fatal-errors.tsv
0 _tmp/spec/cpp/for-expr.tsv
1 _tmp/spec/cpp/for-expr.tsv
2 _tmp/spec/cpp/for-expr.tsv
3 _tmp/spec/cpp/for-expr.tsv
4 _tmp/spec/cpp/for-expr.tsv
5 _tmp/spec/cpp/for-expr.tsv
Expand Down Expand Up @@ -1266,6 +1269,7 @@
5 _tmp/spec/cpp/strict-options.tsv
6 _tmp/spec/cpp/strict-options.tsv
7 _tmp/spec/cpp/strict-options.tsv
8 _tmp/spec/cpp/strict-options.tsv
9 _tmp/spec/cpp/strict-options.tsv
10 _tmp/spec/cpp/strict-options.tsv
11 _tmp/spec/cpp/strict-options.tsv
Expand Down

0 comments on commit 4c35031

Please sign in to comment.