From owner-freebsd-toolchain@freebsd.org Sun Jul 8 15:47:43 2018 Return-Path: Delivered-To: freebsd-toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ED68310321AF for ; Sun, 8 Jul 2018 15:47:42 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic312-21.consmr.mail.ne1.yahoo.com (sonic312-21.consmr.mail.ne1.yahoo.com [66.163.191.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7F7CD7A776 for ; Sun, 8 Jul 2018 15:47:42 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: s9y2gmUVM1kbCX0M6bfRbvwfnJcY49TES96JUtiMJPWHlLl8YJ31xPx2Qog6QAY Yf03FYNIA857ASaud9UP9wz2ys0youkq1HNQ4VlMkocs.bVQ5MzTEB_xfwqsV0LdUxUG1s8qFW3G DWj.7Snbocp1aaE9dSjlcyilwW6S8mCMYvHrpMch7olTlUy_P8wIEYy6msKSGulJVsYQVS7EjfLz s9HE20V0_A7_uzWE.GtYm9gR2PFNmcNxDc6QTk.0VzSix80m7ALGCSz0EAkdU3XJULnzmFvu20WT 5Gbg9jHfflAhoqFyfpedtT8AOWJ_XA6kviVesuWb09JA7JGTAtgE2hqxLaI3aifSmmVMgRA6.Plp LwToPk3n.LPiq8F9FGV14rl6olXShpgl1Vz7jlqfc6gbuELFSpBf0ptK7xGqVK0EeSsVPblWd6wc Net8q1okMA8OFAPrkT7jJAFQ1XhfotVXZMvYUGo5NF27FSdUyVEJW85RK5atAP.ptrxNPpm7.T.N JfHeZveT05EHYhDqdDJkomgJLClfPJUkWv_wF7KjGjcSDX3MBKQLXXJKHpJBXFMLFbPWf7IHNVt3 yt358q5uJTJ8F5zoVzyx3A9twH_gfeZAIO5xcKFafcmfXQpbPoHJlumM2ZtE6MBNxZRx4EDU7hRB d9yfrvJxTQm8tOe0N7u6Dh.wxGoPkrudgZkShlUJWg1nP.wqSYkH1ZMgqe.lCFLuF59zV0eYsZOs 6aMFZg0O.5lL9iXddLtYMa.kbFuiPkv_MSiYeq87g4zLicSB7rFNywh5Mfe1rTNqODaERIuWlVQP c0rJCHvwSjgThTN7cHU4xhbw8MpJf9_iwGP0H1MKy_0HRU4eApEHvJHRbNdLCUHi8p_xS8Q5AG6o RJG75jrHQTh18nKfEoWksk9NBDmzjFVfVb8BfE.qgyM2tkYjy1nwbSvSrJxPISe4qpj0jtkMKpiv OI2hH1YdDFVBZllqLwpMUqZtrowt1szmhE6KWOxNuXgIn Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ne1.yahoo.com with HTTP; Sun, 8 Jul 2018 15:47:41 +0000 Received: from ip70-189-131-151.lv.lv.cox.net (EHLO [192.168.0.105]) ([70.189.131.151]) by smtp412.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 015257d5c8c2cc5bc0d45abc7e5ee1f0 for ; Sun, 08 Jul 2018 15:47:39 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.4 \(3445.8.2\)) Subject: src/contrib/elftoolchain/elfcopy/sections.c underallocates for Elf64_Rela and Elf32_Rela? Message-Id: <79954D9E-0A93-4148-A2C6-B5113E59AE28@yahoo.com> Date: Sun, 8 Jul 2018 08:47:38 -0700 To: FreeBSD Toolchain X-Mailer: Apple Mail (2.3445.8.2) X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jul 2018 15:47:43 -0000 src/contrib/elftoolchain/elfcopy/sections.c has and uses the macro: 716 #define COPYREL(REL, SZ) do { = \ 717 if (nrels =3D=3D 0) { = \ 718 if ((REL##SZ =3D malloc(cap * = \ 719 sizeof(Elf##SZ##_Rel))) =3D=3D NULL) = \ 720 err(EXIT_FAILURE, "malloc failed"); = \ 721 } = \ 722 if (nrels >=3D cap) { = \ 723 cap *=3D 2; = \ 724 if ((REL##SZ =3D realloc(REL##SZ, cap * = \ 725 sizeof(Elf##SZ##_Rel))) =3D=3D NULL) = \ 726 err(EXIT_FAILURE, "realloc failed"); = \ 727 } = \ 728 REL##SZ[nrels].r_offset =3D REL.r_offset; = \ 729 REL##SZ[nrels].r_info =3D REL.r_info; = \ 730 if (s->type =3D=3D SHT_RELA) = \ 731 rela##SZ[nrels].r_addend =3D rela.r_addend; = \ 732 nrels++; = \ 733 } while (0) The context has: 687 Elf32_Rel *rel32; 688 Elf64_Rel *rel64; 689 Elf32_Rela *rela32; 690 Elf64_Rela *rela64; So for, say, COPYREL(rela,64), the macro uses sizeof(Elf64_Rel) instead of sizeof(ELF64_Rela) in malloc and realloc but Elf64_Rela is the larger structure of the two ELF64_ types (by also having .r_addend). The scan build on ci.freebsd.org complains about this: Result of 'realloc' is converted to a pointer of type 'Elf64_Rela', = which is incompatible with sizeof operand type 'Elf64_Rel' So far it does not look like a false-positive to me. =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)