From patchwork Sat Aug 12 12:04:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 800879 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xV0xY22XSz9t3C for ; Sat, 12 Aug 2017 22:07:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752593AbdHLMHm (ORCPT ); Sat, 12 Aug 2017 08:07:42 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:47941 "EHLO mail.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752011AbdHLMHl (ORCPT ); Sat, 12 Aug 2017 08:07:41 -0400 Received: from mail.nwl.cc (orbyte.nwl.cc [127.0.0.1]) by mail.nwl.cc (Postfix) with ESMTP id 5A5AD68252; Sat, 12 Aug 2017 14:07:40 +0200 (CEST) Received: from xsao (localhost [IPv6:::1]) by mail.nwl.cc (Postfix) with ESMTP id 3DEEC681D7; Sat, 12 Aug 2017 14:07:40 +0200 (CEST) From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH 20/51] lib/inet_proto: Make sure destination buffers are NULL-terminated Date: Sat, 12 Aug 2017 14:04:39 +0200 Message-Id: <20170812120510.28750-21-phil@nwl.cc> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170812120510.28750-1-phil@nwl.cc> References: <20170812120510.28750-1-phil@nwl.cc> X-Virus-Scanned: ClamAV using ClamSMTP Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Phil Sutter --- lib/inet_proto.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/inet_proto.c b/lib/inet_proto.c index ceda082b12a2e..87ed4769fc3da 100644 --- a/lib/inet_proto.c +++ b/lib/inet_proto.c @@ -35,8 +35,10 @@ const char *inet_proto_n2a(int proto, char *buf, int len) pe = getprotobynumber(proto); if (pe) { icache = proto; - strncpy(ncache, pe->p_name, 16); - strncpy(buf, pe->p_name, len); + strncpy(ncache, pe->p_name, 15); + ncache[15] = '\0'; + strncpy(buf, pe->p_name, len - 1); + buf[len] = '\0'; return buf; } snprintf(buf, len, "ipproto-%d", proto); @@ -62,7 +64,8 @@ int inet_proto_a2n(const char *buf) pe = getprotobyname(buf); if (pe) { icache = pe->p_proto; - strncpy(ncache, pe->p_name, 16); + strncpy(ncache, pe->p_name, 15); + ncache[15] = '\0'; return pe->p_proto; } return -1;