public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Missing NULL check
@ 2023-09-12 15:40 jacob navia
  2023-09-12 18:50 ` Torbjorn SVENSSON
  2023-09-13  6:50 ` Alan Modra
  0 siblings, 2 replies; 6+ messages in thread
From: jacob navia @ 2023-09-12 15:40 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]

This is very similar to the last one:
FILE:  elf-attrs.c line 232
FUNCTION: elf_new_obj_attr
/* Allocate/find an object attribute.  */
static obj_attribute *
elf_new_obj_attr (bfd *abfd, int vendor, unsigned int tag)
{
  obj_attribute *attr;
  obj_attribute_list *list;
  obj_attribute_list *p;
  obj_attribute_list **lastp;


  if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
    {
      /* Known tags are preallocated.  */
      attr = &elf_known_obj_attributes (abfd)[vendor][tag];
    }
  else
    {
      /* Create a new tag.  */
      list = (obj_attribute_list *)
	bfd_alloc (abfd, sizeof (obj_attribute_list));
      memset (list, 0, sizeof (obj_attribute_list));
      list->tag = tag;
      /* Keep the tag list in order.  */
      lastp = &elf_other_obj_attributes (abfd)[vendor];
      for (p = *lastp; p; p = p->next)
	{
	  if (tag < p->tag)
	    break;
	  lastp = &p->next;
	}
      list->next = *lastp;
      *lastp = list;
      attr = &list->attr;
    }

  return attr;
}

bfd_alloc can return NULL. This is not checked
How to fix:
Add
if (list == NULL) return NULL;



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-13 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 15:40 Missing NULL check jacob navia
2023-09-12 18:50 ` Torbjorn SVENSSON
2023-09-12 19:34   ` Fangrui Song
2023-09-13 10:57     ` Nick Clifton
     [not found]   ` <DS7PR12MB5765DD3A03E4B143B950C3D6CBF1A@DS7PR12MB5765.namprd12.prod.outlook.com>
2023-09-13 14:28     ` jacob navia
2023-09-13  6:50 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).