Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755067AbbKQWtA (ORCPT ); Tue, 17 Nov 2015 17:49:00 -0500 Received: from ares41.inai.de ([46.4.122.207]:35828 "EHLO ares41.inai.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754316AbbKQWs6 (ORCPT ); Tue, 17 Nov 2015 17:48:58 -0500 Date: Tue, 17 Nov 2015 23:48:55 +0100 (CET) From: Jan Engelhardt To: David Miller cc: tj@kernel.org, pablo@netfilter.org, kaber@trash.net, kadlec@blackhole.kfki.hu, lizefan@huawei.com, hannes@cmpxchg.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, daniel@iogearbox.net, daniel.wagner@bmw-carit.de, nhorman@tuxdriver.com, gregkh@linuxfoundation.org Subject: Re: [PATCH 2/5] kernfs: implement kernfs_walk_and_get() In-Reply-To: <20151117.162040.1412296298973879057.davem@davemloft.net> Message-ID: References: <1447789240-29394-1-git-send-email-tj@kernel.org> <1447789240-29394-3-git-send-email-tj@kernel.org> <20151117.162040.1412296298973879057.davem@davemloft.net> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 845 Lines: 26 On Tuesday 2015-11-17 22:20, David Miller wrote: >> + static char path_buf[PATH_MAX]; /* protected by kernfs_mutex */ >> + int len = strlen(path); > ... >> + if (len >= PATH_MAX) >> + return NULL; >> + >> + memcpy(path_buf, path, len + 1); > > static char path_buf[PATH_MAX]; /* protected by kernfs_mutex */ > int len = strlcpy(path_buf, path, PATH_MAX); > ... > if (len >= PATH_MAX) > return NULL; if (len < 0 || len >= PATH_MAX) strlcpy returns a size_t, which, when coerced into an int, could lead to negative numbers. In that sense, "size_t len" probably seems like an even better bet yet. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/