From patchwork Tue Apr 3 21:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 894783 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=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-91383-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="XD2Snxq2"; 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 40G21m5WhCz9s0y for ; Wed, 4 Apr 2018 07:15:39 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; q=dns; s= default; b=hPqEhbfKXh6xmuewK5o9ITfoNQd6Gv/0rnZy42lIGit+tQ7Oua67H wcNBP7z2XtSS6eVzxldVd7y1fEZsj8znizsh+v1rB2ZKdIbcYDXnLEKTGwfN5eO3 yPmOWun7oqtbsPSXiHO8zeMmDWJ6j4IxiSaQmQW8eCaP2A7Dry6YEo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; s=default; bh=Lg/lELhPBV/KP86n3euy1JnhpFU=; b=XD2Snxq2VrAsEvYuecPA9NLbtgxu hiCafkDyTNkDcerMMi6YEB0fsTzIOW5L36pw6E+HkfomEivOC5tpOOKZr7DVlLgr URJdMVFlemrqD8TSFoaaGMi8Xa78cqyVU1LFu+W+Pr+0QQgJ7StteVqqGTW0ta2T dPjRTSZXLCXCo8E= Received: (qmail 111935 invoked by alias); 3 Apr 2018 21:15:27 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 111673 invoked by uid 89); 3 Apr 2018 21:15:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault Subject: [hurd, commited] hurd: Make __if_nametoindex return ENODEV if ifname is too long Date: Tue, 3 Apr 2018 23:14:58 +0200 Message-Id: <20180403211458.12717-1-samuel.thibault@ens-lyon.org> rather than truncating it. * sysdeps/mach/hurd/if_index.c (__if_nametoindex): Return ENODEV if ifname is too long. --- ChangeLog | 4 ++-- sysdeps/mach/hurd/if_index.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd78bf691a..cc9613239d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,8 +35,8 @@ 2018-04-03 Samuel Thibault - * sysdeps/mach/hurd/if_index.c (__if_nametoindex): Always end - ifr.fr_name with a NUL caracter. + * sysdeps/mach/hurd/if_index.c (__if_nametoindex): Return ENODEV if + ifname is too long. 2018-04-03 Wilco Dijkstra diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c index 7f647b7036..b56bfc7ecd 100644 --- a/sysdeps/mach/hurd/if_index.c +++ b/sysdeps/mach/hurd/if_index.c @@ -37,9 +37,13 @@ __if_nametoindex (const char *ifname) if (fd < 0) return 0; - strncpy (ifr.ifr_name, ifname, IFNAMSIZ - 1); - ifr.ifr_name[IFNAMESIZ - 1] = '\0'; + if (strlen (ifname) >= IFNAMSIZ) + { + __set_errno (ENODEV); + return 0; + } + strncpy (ifr.ifr_name, ifname, IFNAMESIZ - 1); if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0) { int saved_errno = errno;