From patchwork Wed Feb 1 20:36:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 722672 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vDFKq4pMtz9sDF for ; Thu, 2 Feb 2017 07:37:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QWiFUp11"; dkim-atps=neutral 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 :content-transfer-encoding; q=dns; s=default; b=yOrAgzHNDpBl0nKW G7HPMZ3fxSCc73+TkrIantl+x+5G79CVX/oLovDJgzK10fRLx+OlX9dNSktdDl0A fGSBusy1kTNKhpoD63sozvqq7X00b2b1+ObELDJ8p0JD478W/ybR9oJzJzfV4CNm dXvqnwZiNObrW5H0xrU6Yqxd5bE= 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 :content-transfer-encoding; s=default; bh=GNot4Oo2DE8RbvpIjd6mTW b/WZo=; b=QWiFUp11seYDIQ0MeuL6Osp3mY8I9hxHs5yiI2n5HFHrwdhhcpPz7M JhIpZYkVshKC24LR5MT/skWo/+lHJYzYsxN59HLJVxaP8RGAEOcLkHsl9RKng03T yRAz/a9lXVsloyRWaUEdErwH2JJgaV0ZEDJMWmCc/UVZwb2IckCew= Received: (qmail 34476 invoked by alias); 1 Feb 2017 20:36:54 -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 34466 invoked by uid 89); 1 Feb 2017 20:36:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Feb 2017 20:36:43 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BEC88813BE for ; Wed, 1 Feb 2017 21:36:41 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iVurWH3UHOfN for ; Wed, 1 Feb 2017 21:36:41 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 9C60C81366 for ; Wed, 1 Feb 2017 21:36:41 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix PR ada/79309 Date: Wed, 01 Feb 2017 21:36:40 +0100 Message-ID: <24362543.rxIXy6VFIO@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 This is the questionable string logic in __gnat_killprocesstree detected by the new -Wstringop-overflow= warning. The fix is Jakub's. Tested on x86_64-suse-linux, applied on the mainline. 2017-02-01 Eric Botcazou Jakub Jelinek PR ada/79309 * adaint.c (__gnat_killprocesstree): Fix broken string handling. Index: adaint.c =================================================================== --- adaint.c (revision 244917) +++ adaint.c (working copy) @@ -3396,14 +3396,16 @@ void __gnat_killprocesstree (int pid, in { if ((d->d_type & DT_DIR) == DT_DIR) { - char statfile[64] = { 0 }; + char statfile[64]; int _pid, _ppid; /* read /proc//stat */ - strncpy (statfile, "/proc/", sizeof(statfile)); - strncat (statfile, d->d_name, sizeof(statfile)); - strncat (statfile, "/stat", sizeof(statfile)); + if (strlen (d->d_name) >= sizeof (statfile) - sizeof ("/proc//stat")) + continue; + strcpy (statfile, "/proc/"); + strcat (statfile, d->d_name); + strcat (statfile, "/stat"); FILE *fd = fopen (statfile, "r");