From patchwork Fri Sep 23 15:56:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 15955 Received: (qmail 25186 invoked by alias); 23 Sep 2016 15:56:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24287 invoked by uid 89); 23 Sep 2016 15:56:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=LONGEST, longest, Hx-languages-length:2413 X-HELO: mail-wm0-f66.google.com Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 23 Sep 2016 15:56:16 +0000 Received: by mail-wm0-f66.google.com with SMTP id 133so3461192wmq.2 for ; Fri, 23 Sep 2016 08:56:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=4ByE6DARCMNw76kxV1UFPedz/F4ypjIwSj8NDv8UWxU=; b=cbDonJtt0C0eOuKxYWJBRCfQbtjLyTfTv6m0TJWOehzEGgh7VvxqYX1ExqmuoGHU2f t/XVJqgKFqt01Ntxey2kuKd+/f9PUkcDO6b/tgRbEmlJ9vC2L9XSfVD7m8qhHwVOF4Qx dByY+YDXEAIqpczW+ROWnIZGqtc7mmLe/8gy0WYvyaZEQBWswQyxQ/Fisj5BnCjKbDDX /3x8INyLZEDEjTt9Ovkn3z9wDNDEa/C6ovGStnBOhRq8OyFmXfRXhQW3FWQ2FegpP2B3 v0ku0CP92lrY29fEZffc/3sMiWYtVKqwpUWmWFN+YXyrjLEpCmzWp+brqYp73rBIARGw Dh4A== X-Gm-Message-State: AA6/9RlSMRdvPbCc3G8krA/fXJiGeN/gisH4KDhpdmqhKc9rbuX0qVRQ+YY9YH8rkMISGA== X-Received: by 10.28.182.9 with SMTP id g9mr3877711wmf.30.1474646174312; Fri, 23 Sep 2016 08:56:14 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com ([86.65.39.12]) by smtp.gmail.com with ESMTPSA id a84sm3755122wme.6.2016.09.23.08.56.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Sep 2016 08:56:13 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] Replace sprintf with xsnprintf in nat/linux-osdata.c Date: Fri, 23 Sep 2016 16:56:04 +0100 Message-Id: <1474646164-14925-1-git-send-email-yao.qi@linaro.org> MIME-Version: 1.0 X-IsSubscribed: yes I see the following build warning when I build GDB with GCC trunk. ../../binutils-gdb/gdb/nat/linux-osdata.c: In function ‘LONGEST linux_xfer_osdata_fds(gdb_byte*, ULONGEST, ULONGEST)’: ../../binutils-gdb/gdb/nat/linux-osdata.c:767:1: error: ‘%s’ directive writing between 0 and 255 bytes into a region of size 11 [-Werror=format-length=] linux_xfer_osdata_fds (gdb_byte *readbuf, ^~~~~~~~~~~~~~~~~~~~~ ../../binutils-gdb/gdb/nat/linux-osdata.c:800:51: note: format output between 7 and 262 bytes into a destination of size 17 sprintf (procentry, "/proc/%s", dp->d_name); ^ ../../binutils-gdb/gdb/nat/linux-osdata.c: In function ‘LONGEST linux_xfer_osdata_threads(gdb_byte*, ULONGEST, ULONGEST)’: ../../binutils-gdb/gdb/nat/linux-osdata.c:555:1: error: ‘%s’ directive writing between 0 and 255 bytes into a region of size 11 [-Werror=format-length=] linux_xfer_osdata_threads (gdb_byte *readbuf, ^~~~~~~~~~~~~~~~~~~~~~~~~ ../../binutils-gdb/gdb/nat/linux-osdata.c:588:51: note: format output between 7 and 262 bytes into a destination of size 17 sprintf (procentry, "/proc/%s", dp->d_name); ^ cc1plus: all warnings being treated as errors The warning is a false positive, but we can workaround it by replacing sprintf with xsnprintf. On the other hand, it is always preferred to use xsnprintf. I'll push it in. gdb: 2016-09-23 Yao Qi * nat/linux-osdata.c (linux_xfer_osdata_threads): Replace sprintf with xsnprintf. (linux_xfer_osdata_fds): Likewise. --- gdb/nat/linux-osdata.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index bf98c96..5b407a4 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -585,7 +585,8 @@ linux_xfer_osdata_threads (gdb_byte *readbuf, || NAMELEN (dp) > sizeof ("4294967295") - 1) continue; - sprintf (procentry, "/proc/%s", dp->d_name); + xsnprintf (procentry, sizeof (procentry), "/proc/%s", + dp->d_name); if (stat (procentry, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) { @@ -797,7 +798,8 @@ linux_xfer_osdata_fds (gdb_byte *readbuf, || NAMELEN (dp) > sizeof ("4294967295") - 1) continue; - sprintf (procentry, "/proc/%s", dp->d_name); + xsnprintf (procentry, sizeof (procentry), "/proc/%s", + dp->d_name); if (stat (procentry, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) {