From patchwork Fri Jul 27 17:12:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 950290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-482552-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GxbTsHXN"; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.b="sGS+HmxG"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41cbBq4bdsz9rxx for ; Sat, 28 Jul 2018 03:13:06 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=B94v4jG93ISVJe+d1No38z3Jfm2pD4jTrtnY9qzS/DpFHCHm3jP/Z UpQAYiWT5cXZJHIsU7HqH4yCxZqCCRRkl1h829ErPAcgqr7aybA0EINIMAlFdQdR UpccQQZTZIjFNgrY6EYMIPEGqWGlmGZO7X33SteAl3eW1pJIXntBn0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=K7o21MtMxVjw2Ih/ftXrXPKiS+s=; b=GxbTsHXNCCZitroCHPui xQADFEZrYfX2Zy8yNoq4HknfriEMiZrAtWstvInuEPmb9bkS0Epwp1Ce+VA1YsZh YuHmeUlJh1DHXVkwi+42+yMIIHFpfHU0YySVSKu4sH4oyQmHyFeEdfvJYndW66la MDSbFi2Rk7UWH6aSAPRsaAk= Received: (qmail 7111 invoked by alias); 27 Jul 2018 17:12:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 7100 invoked by uid 89); 27 Jul 2018 17:12:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Jul 2018 17:12:57 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway23.websitewelcome.com (Postfix) with ESMTP id A2CE929F45 for ; Fri, 27 Jul 2018 12:12:55 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id j6I7fH4y5bXuJj6IIfNIkM; Fri, 27 Jul 2018 12:12:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ins5BDlcnUT47qxzF21TVxW/Phmp2LUyK2B6czvFb0g=; b=sGS+HmxG/hKAnMqyjx8f+Dkwom llL/mrp9rSYM2vobntEiVl9YMRPtqEuE6oTuKQSIKVVcY9GaLJ9ZTTqdWKLD8SmLLRkr9ThHyJduw +dQazjlzpZMo/uy3DfysNBCLv; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:55876 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fj6I6-003KIm-Qu; Fri, 27 Jul 2018 12:12:34 -0500 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: RFA: libiberty: avoid UBSAN complaint in cplus-dem.c Date: Fri, 27 Jul 2018 11:12:33 -0600 Message-ID: <8736w4ppq6.fsf@tromey.com> MIME-Version: 1.0 I built gdb with -fsanitize=undefined, and there was a complaint coming from cplus-dem.c. remember_Btype can call memcpy with a NULL pointer, which is undefined behavior according to the C standard. This patch fixes the problem for me. I tested this by rebuilding gdb (with -fsanitize=undefined) and re-running the test suite. Ok? Tom 2018-07-27 Tom Tromey * cplus-dem.c (remember_Btype): Don't call memcpy with LEN==0. diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c index 6d58bd899bf..4f29d54d089 100644 --- a/libiberty/cplus-dem.c +++ b/libiberty/cplus-dem.c @@ -4471,7 +4471,8 @@ remember_Btype (struct work_stuff *work, const char *start, char *tem; tem = XNEWVEC (char, len + 1); - memcpy (tem, start, len); + if (len > 0) + memcpy (tem, start, len); tem[len] = '\0'; work -> btypevec[index] = tem; }