From patchwork Tue Oct 23 14:21:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 149450 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp760937ljp; Tue, 23 Oct 2018 07:22:10 -0700 (PDT) X-Google-Smtp-Source: AJdET5fx6EGyIt3XoOsHOHZ5RrRJchx9aZt4B4YGI3sHlnyetb5QBuxUwnq1PlZZoqjE2HT63kfa X-Received: by 2002:a63:91c1:: with SMTP id l184mr8461517pge.29.1540304530265; Tue, 23 Oct 2018 07:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540304530; cv=none; d=google.com; s=arc-20160816; b=QK/auxPu560J4D17pbI1j5yM2/hmXfbGtbYapVt5LLVNwffwRQ61+r0Rl7zzdo6Kcl 3lSJfIJ+Y07GGS3v444V9X0shK9Kv3SVZDpHGBXaMAhHD53BitaAYd62YSw/h6K1/rG5 MGeTMGxN4O4+2XE9QpkLxL6OiEteCmoZtfvCMx/q6L66239S43RgMoKwbDHjvGe14bL1 NrI1GKhVimprlRzPqiROV/MfltMclJBbt7zGgZgknonY3n2PQNvuyxxI1NzYWOXr4CTO KombB0p4sH0FKzhRQ5r0eyMW2XUh/m3olNp84PGrhX5Gvi+FFdz+O5qV/M0fbO1Wtar+ Mvng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:dkim-signature :delivered-to:sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=OOMFQjA+taCeaGLRQFYOLYYOzKLblloORc4GMJyO/8U=; b=i8q+NjHG7LlSQIGe2FYlvwZbEfc5lBtodVKrexQ8nYf/PR8aXJGoNPyUAkDBaN/9RI OOucXSkhQiiX4WA7iicWMre4XYQxJUbZoH8uDNUrb8pvM8dUaxUzEzhS6Gq0tY2zdVcq 7wwYdLG8HnOHD+N5CuXACSwl7jMppKx6rmdZkVDJ28FJw1pmhssrLSfRB0Odo0zugBO7 M7Zl05gz+F2Ztz9MTFHnBj1FUycCya4jqiHIsVAHLWhWtaiqxTNYSEfAgDHZl4OhoFCp dMnDVoOIdAUN2MiYm0PiCz3+IzmU5qyArrz4l58u29bv7xIDHhFBKFtejrU78zLJlboJ 1gLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="gRU/vQRE"; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fuLJ6eV9; spf=pass (google.com: domain of binutils-return-103981-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="binutils-return-103981-patch=linaro.org@sourceware.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p186-v6si1484713pfb.200.2018.10.23.07.22.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 07:22:10 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-103981-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="gRU/vQRE"; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fuLJ6eV9; spf=pass (google.com: domain of binutils-return-103981-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="binutils-return-103981-patch=linaro.org@sourceware.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=N9eURY7yALArnNdMhA31/X/dynfR9 DsB42s7O4oq7MHMs9sNp5j2LrpTiiUEKGacZggFCCzsKhcUKh4kipXQYjIdRj4ar 13Gu0tZ/3yKzU5ihURUZ6wv1hRdJq8d34uFELU/P+4/1d0KDWumI28y2iR5/gAw9 R3vV51GFYy3/JY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=l/Cz9n7ULWHNdmn/NAMnUrod4eg=; b=gRU /vQREhgJwm8aJkXKdKrUkojbw+5WxfiHOxRw2xt35zwr2L+W3nHjHTtBRQD7GIL+ +A/xOdXeU9IDDH2AdiiiHizDaOQ8MyuPHouqBMvxPV0Mjb9JHG6W66ZdzVMdHLSk TWLjZ2LJyPSdjtbOM9IqYq24T635fyXDhsa8Mmqg= Received: (qmail 28445 invoked by alias); 23 Oct 2018 14:21:57 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Delivered-To: mailing list binutils@sourceware.org Received: (qmail 28422 invoked by uid 89); 23 Oct 2018 14:21:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=browsing X-HELO: mail-ua1-f53.google.com Received: from mail-ua1-f53.google.com (HELO mail-ua1-f53.google.com) (209.85.222.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Oct 2018 14:21:55 +0000 Received: by mail-ua1-f53.google.com with SMTP id j13so567525ual.0 for ; Tue, 23 Oct 2018 07:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:from:date:message-id:subject:to; bh=hDNNORSX2zUxXjbgrkGync63Cj/kBayOzvuJJQDvSzQ=; b=fuLJ6eV900OeD5jIEiVHNFjXYuX4YHZR1w0uL5awG+xK4powiTnHTDw53/7idTpGsn bCfsdkrdiUdPDH49i8eDLyJZRvlGTVGdUu2krm25Xcx7RBKYg/PshmBj0d9sfkexuhJI 6t2O7DLPR1Z9blnpdpvoEocR1TjKr6mPP2fOk= MIME-Version: 1.0 From: Christophe Lyon Date: Tue, 23 Oct 2018 16:21:41 +0200 Message-ID: Subject: [ARM] Avoid dereferencing null pointers To: binutils X-IsSubscribed: yes Hi, While building an ARM FDPIC toolchain with a compiler generating Thumb code, I face a couple of null pointer dereferences in cmse_scan(). When browsing ld-uClibc.so.1, all the external symbols have no info in sym_hashes (sym_hashes[X] == NULL), and when handling libgcc_s.so.1 for the 2nd time in the same command, sym_hashes == NULL. I don't know why this doesn't happen with a compiler generating Arm code (ie. why the symbol tables are handled differently), but the attached small patch prevents the linker from crashing. OK? Thanks, Christophe 2018-10-23 Christophe Lyon * elf32-arm.c (cmse_scan): Avoid dereferencing NULL pointers. diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 9c61181..6ea348b 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -5939,7 +5939,16 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab, } else { + /* No hash table, stop iterating. */ + if (sym_hashes == NULL) + break; + cmse_hash = elf32_arm_hash_entry (sym_hashes[i - ext_start]); + + /* Avoid dereferencing if info is not present. */ + if (cmse_hash == NULL) + continue; + sym_name = (char *) cmse_hash->root.root.root.string; /* Not a special symbol. */