Skip to content

ASan strtol interceptor breaks errno on Windows #34485

@rnk

Description

@rnk
Bugzilla Link 35137
Version unspecified
OS Windows NT
CC @markmentovai,@Predelnik,@vitalybuka

Extended Description

Running this program on Windows prints "errno: 34" without asan and "errno: 0" with asan:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
void print_strtol_results(const char *input) {
  char *end = 0;
  long result = strtol(input, &end, 10);
  int err = errno;
  printf("input: %s, end: %s, result: %ld, errno: %d\n", input, end, result, err);
}
int main() {
  //print_strtol_results("2147483647");
  print_strtol_results("2147483648");
  printf("&errno: %p, errno: %d\n", &errno, errno);
  return 0;
}

This is because ASan intercepts many versions of strtol and redirects them all to itself. It then delegates to ntdll!strtol, which doesn't set errno, because errno is a CRT concept, and ntdll is layered below the CRT.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions