Bug 31276 - Wrong condition for heap allocation in qsort_r
Summary: Wrong condition for heap allocation in qsort_r
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: 2.39
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-22 19:54 UTC by Xi Ruoyao
Modified: 2024-01-27 11:09 UTC (History)
3 users (show)

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 Xi Ruoyao 2024-01-22 19:54:25 UTC
/* Align to the maximum size used by the swap optimization.  */
  _Alignas (uint64_t) char tmp[QSORT_STACK_SIZE];
  size_t total_size = total_elems * size;
  char *buf;

  if (size > INDIRECT_SORT_SIZE_THRES)
    total_size = 2 * total_elems * sizeof (void *) + size;

  if (total_size < sizeof buf)
    buf = tmp;
  else
    { /* allocate buf on heap ... */ }

Here "sizeof buf" is the size of a pointer, but (obviously?) we want QSORT_STACK_SIZE here, i.e. "sizeof tmp".