Skip to content

Commit 7dad989

Browse files
committed
fix(run): propagate sanitizer flags to runtime + improve double free diagnostics
- add useSan parameter to run_cmd_live_filtered_capture - propagate --san / --ubsan from RunCommand → RunProcess - inject ASAN_OPTIONS and UBSAN_OPTIONS at runtime - ensure all call sites pass sanitizer flag correctly - improve runtime double free detection pipeline note: enables proper AddressSanitizer output for script mode
1 parent 23fae62 commit 7dad989

6 files changed

Lines changed: 226 additions & 35 deletions

File tree

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ namespace vix::commands::RunCommand::detail
491491
const std::string &cmd,
492492
const std::string &spinnerLabel,
493493
bool passthroughRuntime,
494-
int timeoutSec = 0);
494+
int timeoutSec = 0,
495+
bool useSan = false);
495496

496497
/**
497498
* @brief Run a command and capture its output plus exit code.

src/commands/RunCommand.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ namespace
582582
testCmd,
583583
"",
584584
true,
585-
0);
585+
0,
586+
false);
586587

587588
const int testExit = tr.exitCode;
588589

@@ -602,13 +603,15 @@ namespace
602603

603604
if (!log.empty())
604605
{
606+
const fs::path diagnosticPath = *testExe;
607+
605608
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
606609
log,
607-
testExe->string(),
610+
diagnosticPath,
608611
"Test crashed");
609612

610613
if (!handled &&
611-
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, testExe->string()))
614+
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, diagnosticPath))
612615
{
613616
handled = true;
614617
}
@@ -667,7 +670,8 @@ namespace
667670
runCmd,
668671
"",
669672
true,
670-
timeoutSec);
673+
timeoutSec,
674+
opt.enableSanitizers || opt.enableUbsanOnly);
671675

672676
int runExit = rr.exitCode;
673677

@@ -687,13 +691,15 @@ namespace
687691

688692
if (!log.empty())
689693
{
694+
const fs::path diagnosticPath = opt.singleCpp ? opt.cppFile : exePath;
695+
690696
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
691697
log,
692-
exePath,
698+
diagnosticPath,
693699
failureContext);
694700

695701
if (!handled &&
696-
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, exePath))
702+
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, diagnosticPath))
697703
{
698704
handled = true;
699705
}
@@ -791,7 +797,8 @@ namespace
791797
cmd,
792798
"",
793799
false,
794-
0);
800+
0,
801+
false);
795802

796803
const int code = cr.exitCode;
797804
if (code != 0)
@@ -1000,7 +1007,8 @@ namespace
10001007
oss.str(),
10011008
"",
10021009
false,
1003-
0);
1010+
0,
1011+
false);
10041012

10051013
const int code = cr.exitCode;
10061014
if (code != 0)

src/commands/run/RunProcess.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ namespace vix::commands::RunCommand::detail
946946
::kill(pid, sig);
947947
}
948948

949-
void child_exec_shell(const std::string &cmd, int masterFd, int slaveFd)
949+
void child_exec_shell(const std::string &cmd, int masterFd, int slaveFd, bool useSan)
950950
{
951951
struct sigaction saChild{};
952952
saChild.sa_handler = SIG_DFL;
@@ -956,20 +956,24 @@ namespace vix::commands::RunCommand::detail
956956

957957
::setsid();
958958

959-
::setenv("ASAN_OPTIONS",
960-
"abort_on_error=1:"
961-
"detect_leaks=1:"
962-
"symbolize=1:"
963-
"allocator_may_return_null=1:"
964-
"fast_unwind_on_malloc=0:"
965-
"strict_init_order=1:"
966-
"check_initialization_order=1:"
967-
"color=never",
968-
1);
969-
970-
::setenv("UBSAN_OPTIONS",
971-
"halt_on_error=1:print_stacktrace=1:color=never",
972-
1);
959+
if (useSan)
960+
{
961+
::setenv("ASAN_OPTIONS",
962+
"abort_on_error=1:"
963+
"halt_on_error=1:"
964+
"print_stacktrace=1:"
965+
"detect_leaks=1:"
966+
"symbolize=1:"
967+
"fast_unwind_on_malloc=0:"
968+
"strict_init_order=1:"
969+
"check_initialization_order=1:"
970+
"color=never",
971+
1);
972+
973+
::setenv("UBSAN_OPTIONS",
974+
"halt_on_error=1:print_stacktrace=1:color=never",
975+
1);
976+
}
973977

974978
::close(masterFd);
975979

@@ -1057,7 +1061,8 @@ namespace vix::commands::RunCommand::detail
10571061
const std::string &cmd,
10581062
const std::string &spinnerLabel,
10591063
bool passthroughRuntime,
1060-
int timeoutSec)
1064+
int timeoutSec,
1065+
bool useSan)
10611066
{
10621067
SigintGuard sigGuard;
10631068
LiveRunResult result;
@@ -1081,7 +1086,7 @@ namespace vix::commands::RunCommand::detail
10811086
}
10821087

10831088
if (pid == 0)
1084-
child_exec_shell(cmd, pty.masterFd, pty.slaveFd);
1089+
child_exec_shell(cmd, pty.masterFd, pty.slaveFd, useSan);
10851090

10861091
close_safe(pty.slaveFd);
10871092
::setpgid(pid, pid);
@@ -1339,7 +1344,8 @@ namespace vix::commands::RunCommand::detail
13391344
cmd,
13401345
spinnerLabel,
13411346
false,
1342-
0);
1347+
0,
1348+
false);
13431349
return r.exitCode;
13441350
#endif
13451351
}

src/commands/run/RunScript.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ namespace vix::commands::RunCommand::detail
633633
cmdRun,
634634
"",
635635
isPlainScript,
636-
effective_timeout_sec(opt));
636+
effective_timeout_sec(opt),
637+
opt.enableSanitizers || opt.enableUbsanOnly);
637638

638639
int runCode = normalize_exit_code(rr.exitCode);
639640

@@ -748,7 +749,8 @@ namespace vix::commands::RunCommand::detail
748749
cmdRun,
749750
"",
750751
true,
751-
effective_timeout_sec(opt));
752+
effective_timeout_sec(opt),
753+
opt.enableSanitizers || opt.enableUbsanOnly);
752754

753755
int runCode = normalize_exit_code(rr.exitCode);
754756

@@ -834,7 +836,8 @@ namespace vix::commands::RunCommand::detail
834836
directPlan.compileCmd,
835837
"Compiling script...",
836838
false,
837-
0);
839+
0,
840+
o.enableSanitizers || o.enableUbsanOnly);
838841

839842
if (build.exitCode != 0)
840843
{

src/commands/run/detail/DirectScriptRunner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ namespace vix::commands::RunCommand::detail
434434
plan.compileCmd,
435435
"Compiling script...",
436436
false,
437-
0);
437+
0,
438+
opt.enableSanitizers || opt.enableUbsanOnly);
438439

439440
if (build.exitCode != 0)
440441
{
@@ -459,7 +460,8 @@ namespace vix::commands::RunCommand::detail
459460
plan.runCmd,
460461
"Running script...",
461462
plan.passthroughRuntime,
462-
plan.effectiveTimeoutSec);
463+
plan.effectiveTimeoutSec,
464+
opt.enableSanitizers || opt.enableUbsanOnly);
463465

464466
handle_runtime_exit_code(run.exitCode, "run", run.failureHandled);
465467
return run.exitCode;

0 commit comments

Comments
 (0)