瀏覽代碼

Set errno to ENOMEM when simulating a malloc failure.

Per malloc(3):

    The  UNIX  98  standard requires malloc(), calloc(), and realloc() to set
    errno to ENOMEM upon failure.  Glibc assumes that this is done (and the
    glibc versions of these routines do this); if you use a private malloc
    implementation that does not set errno, then certain library routines may
    fail without having a reason in errno.

Notably, thread_test otherwise fails an assertion deep in glibc.

Change-Id: Ia2c0ab306987476e7d6570d4bbf04a2641398925
Reviewed-on: https://boringssl-review.googlesource.com/5111
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin 9 年之前
committed by Adam Langley
父節點
當前提交
2b2b0f909d
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. +4
    -0
      crypto/test/malloc.cc

+ 4
- 0
crypto/test/malloc.cc 查看文件

@@ -34,6 +34,7 @@
#if defined(__linux__) && defined(OPENSSL_GLIBC) && !defined(OPENSSL_ARM) && \
!defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN)

#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -118,6 +119,7 @@ extern "C" {

void *malloc(size_t size) {
if (should_fail_allocation()) {
errno = ENOMEM;
return NULL;
}

@@ -126,6 +128,7 @@ void *malloc(size_t size) {

void *calloc(size_t num_elems, size_t size) {
if (should_fail_allocation()) {
errno = ENOMEM;
return NULL;
}

@@ -134,6 +137,7 @@ void *calloc(size_t num_elems, size_t size) {

void *realloc(void *ptr, size_t size) {
if (should_fail_allocation()) {
errno = ENOMEM;
return NULL;
}



Loading…
取消
儲存