Bug 27870 - MALLOC_CHECK_ causes realloc(valid_ptr, TOO_LARGE) to not set ENOMEM
Summary: MALLOC_CHECK_ causes realloc(valid_ptr, TOO_LARGE) to not set ENOMEM
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: malloc (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: 2.34
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-15 16:43 UTC by Pádraig Brady
Modified: 2021-05-19 07:47 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pádraig Brady 2021-05-15 16:43:59 UTC
With MALLOC_CHECK_ env var set to valid values (1,2, or 3),
the realloc implementation doesn't set ENOMEM when it should.

Running the following shows that errno is incorrectly set to 0:


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main ()
{
  void *p;
  void* p2 = malloc ((unsigned long) 1);
  errno = 0;
  p = realloc (p2, (unsigned long) PTRDIFF_MAX + 1);
  fprintf (stderr, "p=%p errno=%d\n", p, errno);
  return 0;
}


gcc realloc.c
MALLOC_CHECK_=1 ./a.out
Comment 1 Andreas Schwab 2021-05-17 19:43:31 UTC
Fixed in 2.34
Comment 2 Pádraig Brady 2021-05-19 07:47:47 UTC
https://sourceware.org/git/?p=glibc.git;a=commit;h=c6b6b4f2

Thank you