From patchwork Tue Dec 23 11:39:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 42566 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B64192188F for ; Tue, 23 Dec 2014 11:41:01 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf3945757lab.11 for ; Tue, 23 Dec 2014 03:41:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=2LjnQrsOTZdBt/mb8FYEX0m6vGFHo8KzaAxr2GUm9yA=; b=aMKO9hDTsbGLi7dHQkMQx33G/Y3l60llFM4CiKYoYEAHNWINxW7NzhaYTE5HLbcMJ3 zdJeEDLQ4opOSToTqFhc/IZmySFh6E2QZDO1Wte69tPmC9YFlHxzT2uBBS7VGLh3qHRz J2AO3KBmoxAThyp8SkHlG9wJVw/ff9XjsK10h6y3BKCgNo/oSOGZOLwS36bQqpFG5pxS /3FAK6lsW5sSZjvrq900mm61YHx+E38V7tqSE17fKK7LzXOctuQMpB21jy49hFFTmJUg XdoWY09W220lKVcZ/Js/HArBH7SHy66ptHfezME19uTe+bnt9LVT0gYPPNZLRt64B9rg 8t+Q== X-Gm-Message-State: ALoCoQkiwatSx6kCsGrdxfR6rCwOTb/1Ij1+PkK7dJWeS+uuYllYtCM0xyGBjR9EdbFsDJl0HA8v X-Received: by 10.152.42.196 with SMTP id q4mr121953lal.6.1419334860656; Tue, 23 Dec 2014 03:41:00 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.169 with SMTP id uf9ls512941lac.75.gmail; Tue, 23 Dec 2014 03:41:00 -0800 (PST) X-Received: by 10.112.64.35 with SMTP id l3mr7722058lbs.82.1419334860305; Tue, 23 Dec 2014 03:41:00 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id pe5si9455150lbc.40.2014.12.23.03.41.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 23 Dec 2014 03:41:00 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gd6so5431206lab.29 for ; Tue, 23 Dec 2014 03:41:00 -0800 (PST) X-Received: by 10.112.84.225 with SMTP id c1mr5659440lbz.22.1419334860209; Tue, 23 Dec 2014 03:41:00 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1300485lbb; Tue, 23 Dec 2014 03:40:59 -0800 (PST) X-Received: by 10.140.38.139 with SMTP id t11mr32346977qgt.83.1419334858641; Tue, 23 Dec 2014 03:40:58 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id y11si22950999qaf.75.2014.12.23.03.40.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 23 Dec 2014 03:40:58 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y3Npf-000256-Ml; Tue, 23 Dec 2014 11:40:55 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y3NpJ-0001yI-9N for lng-odp@lists.linaro.org; Tue, 23 Dec 2014 11:40:33 +0000 Received: by mail-la0-f42.google.com with SMTP id gd6so5430544lab.29 for ; Tue, 23 Dec 2014 03:40:27 -0800 (PST) X-Received: by 10.112.55.101 with SMTP id r5mr9547545lbp.98.1419334827768; Tue, 23 Dec 2014 03:40:27 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id cy6sm5784098lbb.39.2014.12.23.03.40.26 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 23 Dec 2014 03:40:27 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 23 Dec 2014 14:39:59 +0300 Message-Id: <1419334799-19653-5-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1419334799-19653-1-git-send-email-maxim.uvarov@linaro.org> References: <1419334799-19653-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 4/4] linux-generic: correctly copy pktio name with snprintf X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Fix covery waring for: platform/linux-generic/odp_packet_io.c: 250 in odp_pktio_open() CID 83058: Buffer not null terminated (BUFFER_SIZE_WARNING) And make all other code common. Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_packet_io.c | 11 ++++------- platform/linux-generic/odp_packet_socket.c | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 9376b6f..59590d2 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -247,7 +247,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) return ODP_PKTIO_INVALID; done: - strncpy(pktio_entry->s.name, dev, IFNAMSIZ); + snprintf(pktio_entry->s.name, IFNAMSIZ, "%s", dev); unlock_entry_classifier(pktio_entry); return id; } @@ -560,8 +560,7 @@ int odp_pktio_mtu(odp_pktio_t id) } sockfd = sockfd_from_pktio_entry(entry); - strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); - ifr.ifr_name[IFNAMSIZ - 1] = 0; + snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name); ret = ioctl(sockfd, SIOCGIFMTU, &ifr); if (ret < 0) { @@ -596,8 +595,7 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) } sockfd = sockfd_from_pktio_entry(entry); - strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); - ifr.ifr_name[IFNAMSIZ - 1] = 0; + snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name); ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); if (ret < 0) { @@ -644,8 +642,7 @@ int odp_pktio_promisc_mode(odp_pktio_t id) } sockfd = sockfd_from_pktio_entry(entry); - strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); - ifr.ifr_name[IFNAMSIZ - 1] = 0; + snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name); ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); if (ret < 0) { diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index 340da88..3d3f4cb 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -238,7 +238,7 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev, /* get if index */ memset(ðreq, 0, sizeof(struct ifreq)); - strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1); + snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev); err = ioctl(sockfd, SIOCGIFINDEX, ðreq); if (err != 0) { perror("setup_pkt_sock() - ioctl(SIOCGIFINDEX)"); @@ -248,7 +248,7 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev, /* get MAC address */ memset(ðreq, 0, sizeof(ethreq)); - strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1); + snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev); err = ioctl(sockfd, SIOCGIFHWADDR, ðreq); if (err != 0) { perror("setup_pkt_sock() - ioctl(SIOCGIFHWADDR)"); @@ -811,7 +811,7 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t *const pkt_sock, /* get MAC address */ memset(ðreq, 0, sizeof(ethreq)); - strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1); + snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev); ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, ðreq); if (ret != 0) { perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");