Check the result of two bfd_alloc calls in elf.c

Project / Subsystem

binutils / binutils

Date

2026-07-07

Proposer

Alan Modra <amodra@gmail.com>

Source type

public_inbox

Consensus

Proposed

Sentiment

/10

Technical tradeoffs

  • Adding null checks increases code verbosity slightly but significantly improves stability.
  • Removing unnecessary casts can improve code clarity and potentially avoid subtle type-related issues.

All attributes

project
binutils
subsystem
binutils
patch_id
discussion_id
aky79AMZtaPhprfE@squeak.grove.modra.org
source_type
public_inbox
title
Check the result of two bfd_alloc calls in elf.c
headline
Handle NULL return from bfd_alloc/zalloc in elf.c
tldr
Adds checks for NULL return values from bfd_alloc and bfd_zalloc in elf.c to prevent potential crashes.
proposer
Alan Modra <amodra@gmail.com>
consensus
Proposed
outcome
proposed
sentiment_score
technical_tradeoffs
  • Adding null checks increases code verbosity slightly but significantly improves stability.
  • Removing unnecessary casts can improve code clarity and potentially avoid subtle type-related issues.
series_id
series_role
standalone
series_parts
[]
tags
  • binutils
  • elf
  • memory management
  • robustness
  • bug fix
bugzilla_url
date
2026-07-07T00:00:00.000Z

Check the result of two bfd_alloc calls in elf.c

This patch addresses a potential issue in binutils’ elf.c by adding checks for NULL return values from bfd_zalloc and bfd_alloc calls. It also removes unnecessary casts on the return values of these allocation functions and simplifies variable usage in a few cases, aiming to improve robustness.