1

When using Address Sanitizer when either of ASAN or the actual program fails, the exitcode is always 1. How can I differentiate one from the other? I tried setting exitcode option in ASAN_OPTIONS to something other than 1, but still ASAN is exiting with 1. What can I do?

Here is the sample code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char *argv[]) {
    char *s = malloc(5);
    strcpy(s, "Hello world!");
    printf("string is: %s\n", s);
    //free(s);
    return 0;
}

Here is the command used to compile: gcc -g -fsanitize=address -o /tmp/tmp.bin /tmp/tmp.c

Here is the command used to execute: ASAN_OPTIONS=exitcode=0 /tmp/tmp.bin ; echo $?

Here whatever exitcode I used (other than 0), I'm getting 1 as output of echo $?

15
  • Do you get ASAN errors without the script? If so, fix them now so you don't have to worry about the exit code. Commented Dec 12, 2024 at 16:37
  • @StephenNewell what you are suggesting is a workaround. I'm expecting an actual solution to this issue Commented Dec 12, 2024 at 16:40
  • 1
    I tried setting exitcode option in ASAN_OPTIONS to something other than 1, but still ASAN is exiting with 1. - so maybe it's because your program is exiting with 1? Commented Dec 12, 2024 at 16:59
  • 1
    @SouravKannanthaB Well, I certainly didn't do any extensive testing, but with the code you posted and invocation with exitcode=123, it returns 123 for me. Using gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0 Commented Dec 12, 2024 at 17:30
  • 1
    @EugeneSh. Yes, found it, ASAN error is happening in a child process and it is exiting as expected. Parent process is then catching it and exiting with 1. Thanks for your help. Commented Dec 12, 2024 at 17:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.