From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by sourceware.org (Postfix) with ESMTP id 31E78385B831 for ; Mon, 23 Mar 2020 16:17:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 31E78385B831 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-6ZRg8rUeMWWqR6WI3JW53w-1; Mon, 23 Mar 2020 12:17:40 -0400 X-MC-Unique: 6ZRg8rUeMWWqR6WI3JW53w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0DBB1005513 for ; Mon, 23 Mar 2020 16:17:39 +0000 (UTC) Received: from comet.redhat.com (ovpn-114-41.ams2.redhat.com [10.36.114.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BCC460FC1 for ; Mon, 23 Mar 2020 16:17:38 +0000 (UTC) From: Nick Clifton To: binutils@sourceware.org Subject: Commit: wrstabs.c: replace assertions with error returns Date: Mon, 23 Mar 2020 16:17:36 +0000 Message-ID: <87369zgi5b.fsf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Status: No, score=-31.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2020 16:17:44 -0000 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi Guys, I am applying the attached patch to replace the assertions in the STABS decoder with error returns. We have recently had a PR filed against this file (PR 25714) because an assertion was being triggered and so forcing a core dump. Cheers Nick binutils/ChangeLog 2020-03-23 Nick Clifton =09PR 25714 =09* wrstabs.c (stab_pop_type): Replace assertion with error return. =09* write_stabs_in_sections_debugging_info: Likewise. =09* stab_enum_type: Likewise. =09* stab_modify_type: Likewise. =09* stab_struct_field: Likewise. =09* stab_end_struct_type: Likewise. =09* stab_start_class_type: Likewise. =09* stab_class_static_member: Likewise. =09* stab_class_baseclass: Likewise. =09* stab_class_start_method: Likewise. =09* stab_class_method_var: Likewise. =09* stab_class_end_method: Likewise. =09* stab_end_class_type: Likewise. =09* stab_typedef_type: Likewise. =09* stab_start_function: Likewise. =09* stab_end_block: Likewise. =09* stab_lineno: Likewise. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=pr25714.patch Content-Transfer-Encoding: quoted-printable diff --git a/binutils/wrstabs.c b/binutils/wrstabs.c index 34c9ef9d2d..86abec2765 100644 --- a/binutils/wrstabs.c +++ b/binutils/wrstabs.c @@ -437,7 +437,8 @@ stab_pop_type (struct stab_write_handle *info) char *ret; =20 s =3D info->type_stack; - assert (s !=3D NULL); + if (s =3D=3D NULL) + return NULL; =20 info->type_stack =3D s->next; =20 @@ -511,7 +512,8 @@ write_stabs_in_sections_debugging_info (bfd *abfd, void= *dhandle, if (! debug_write (dhandle, &stab_fns, (void *) &info)) return FALSE; =20 - assert (info.pending_lbrac =3D=3D (bfd_vma) -1); + if (info.pending_lbrac !=3D (bfd_vma) -1) + return FALSE; =20 /* Output a trailing N_SO. */ if (! stab_write_symbol (&info, N_SO, 0, info.last_text_address, @@ -788,7 +790,8 @@ stab_enum_type (void *p, const char *tag, const char **= names, =20 if (names =3D=3D NULL) { - assert (tag !=3D NULL); + if (tag =3D=3D NULL) +=09return FALSE; =20 buf =3D (char *) xmalloc (10 + strlen (tag)); sprintf (buf, "xe%s:", tag); @@ -850,7 +853,8 @@ stab_modify_type (struct stab_write_handle *info, int m= od, long tindex; char *s, *buf; =20 - assert (info->type_stack !=3D NULL); + if (info->type_stack =3D=3D NULL) + return FALSE; targindex =3D info->type_stack->index; =20 if (targindex <=3D 0 @@ -1360,8 +1364,9 @@ stab_struct_field (void *p, const char *name, bfd_vma= bitpos, =20 /* Add this field to the end of the current struct fields, which is currently on the top of the stack. */ + if (info->type_stack->fields =3D=3D NULL) + return FALSE; =20 - assert (info->type_stack->fields !=3D NULL); n =3D (char *) xmalloc (strlen (info->type_stack->fields) =09=09=09+ strlen (name) =09=09=09+ strlen (s) @@ -1416,7 +1421,8 @@ stab_end_struct_type (void *p) unsigned int size; char *fields, *first, *buf; =20 - assert (info->type_stack !=3D NULL && info->type_stack->fields !=3D NULL= ); + if (info->type_stack =3D=3D NULL || info->type_stack->fields =3D=3D NULL= ) + return FALSE; =20 definition =3D info->type_stack->definition; tindex =3D info->type_stack->index; @@ -1463,13 +1469,15 @@ stab_start_class_type (void *p, const char *tag, un= signed int id, =20 if (ownvptr) =09{ -=09 assert (info->type_stack->index > 0); +=09 if (info->type_stack->index < 1) +=09 return FALSE; =09 vtable =3D (char *) xmalloc (20); =09 sprintf (vtable, "~%%%ld", info->type_stack->index); =09} else =09{ -=09 assert (vstring); +=09 if (vstring =3D=3D NULL) +=09 return FALSE; =09 vtable =3D (char *) xmalloc (strlen (vstring) + 3); =09 sprintf (vtable, "~%%%s", vstring); =09 free (vstring); @@ -1499,7 +1507,8 @@ stab_class_static_member (void *p, const char *name, = const char *physname, /* Add this field to the end of the current struct fields, which is currently on the top of the stack. */ =20 - assert (info->type_stack->fields !=3D NULL); + if (info->type_stack->fields =3D=3D NULL) + return FALSE; n =3D (char *) xmalloc (strlen (info->type_stack->fields) =09=09=09+ strlen (name) =09=09=09+ strlen (s) @@ -1579,7 +1588,8 @@ stab_class_baseclass (void *p, bfd_vma bitpos, bfd_bo= olean is_virtual, =20 /* Add the new baseclass to the existing ones. */ =20 - assert (info->type_stack !=3D NULL && info->type_stack->fields !=3D NULL= ); + if (info->type_stack =3D=3D NULL || info->type_stack->fields =3D=3D NULL= ) + return FALSE; =20 if (info->type_stack->baseclasses =3D=3D NULL) c =3D 0; @@ -1611,7 +1621,8 @@ stab_class_start_method (void *p, const char *name) struct stab_write_handle *info =3D (struct stab_write_handle *) p; char *m; =20 - assert (info->type_stack !=3D NULL && info->type_stack->fields !=3D NULL= ); + if (info->type_stack =3D=3D NULL || info->type_stack->fields =3D=3D NULL= ) + return FALSE; =20 if (info->type_stack->methods =3D=3D NULL) { @@ -1656,7 +1667,8 @@ stab_class_method_var (struct stab_write_handle *info= , const char *physname, context =3D stab_pop_type (info); } =20 - assert (info->type_stack !=3D NULL && info->type_stack->methods !=3D NUL= L); + if (info->type_stack =3D=3D NULL || info->type_stack->methods =3D=3D NUL= L) + return FALSE; =20 switch (visibility) { @@ -1757,7 +1769,8 @@ stab_class_end_method (void *p) { struct stab_write_handle *info =3D (struct stab_write_handle *) p; =20 - assert (info->type_stack !=3D NULL && info->type_stack->methods !=3D NUL= L); + if (info->type_stack =3D=3D NULL || info->type_stack->methods =3D=3D NUL= L) + return FALSE; =20 /* We allocated enough room on info->type_stack->methods to add the trailing semicolon. */ @@ -1776,7 +1789,10 @@ stab_end_class_type (void *p) unsigned int i =3D 0; char *buf; =20 - assert (info->type_stack !=3D NULL && info->type_stack->fields !=3D NULL= ); + if (info->type_stack =3D=3D NULL + || info->type_stack->string =3D=3D NULL + || info->type_stack->fields =3D=3D NULL) + return FALSE; =20 /* Work out the size we need to allocate for the class definition. */ =20 @@ -1849,7 +1865,8 @@ stab_typedef_type (void *p, const char *name) struct string_hash_entry *h; =20 h =3D string_hash_lookup (&info->typedef_hash, name, FALSE, FALSE); - assert (h !=3D NULL && h->index > 0); + if (h =3D=3D NULL || h->index < 1) + return FALSE; =20 return stab_push_defined_type (info, h->index, h->size); } @@ -2081,7 +2098,8 @@ stab_start_function (void *p, const char *name, bfd_b= oolean globalp) struct stab_write_handle *info =3D (struct stab_write_handle *) p; char *rettype, *buf; =20 - assert (info->nesting =3D=3D 0 && info->fun_offset =3D=3D -1); + if (info->nesting !=3D 0 || info->fun_offset !=3D -1) + return FALSE; =20 rettype =3D stab_pop_type (info); =20 @@ -2223,7 +2241,8 @@ stab_end_block (void *p, bfd_vma addr) info->pending_lbrac =3D (bfd_vma) -1; } =20 - assert (info->nesting > 0); + if (info->nesting < 1) + return FALSE; =20 --info->nesting; =20 @@ -2250,7 +2269,8 @@ stab_lineno (void *p, const char *file, unsigned long= lineno, bfd_vma addr) { struct stab_write_handle *info =3D (struct stab_write_handle *) p; =20 - assert (info->lineno_filename !=3D NULL); + if (info->lineno_filename =3D=3D NULL) + return FALSE; =20 if (addr > info->last_text_address) info->last_text_address =3D addr; --=-=-=--