From patchwork Fri Jun 27 18:43:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 365107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E1B97140087 for ; Sat, 28 Jun 2014 04:43:11 +1000 (EST) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5RIh86b028541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Jun 2014 18:43:09 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5RIh8R7024412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 27 Jun 2014 18:43:08 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1X0b76-0000ld-EF; Fri, 27 Jun 2014 11:43:08 -0700 Received: from acsinet22.oracle.com ([141.146.126.238]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1X0b73-0000lT-Nt for fedfs-utils-devel@oss.oracle.com; Fri, 27 Jun 2014 11:43:05 -0700 Received: from aserp1020.oracle.com (aserp1020.oracle.com [141.146.126.67]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5RIh5mo024206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 Jun 2014 18:43:05 GMT Received: from mail-ig0-f172.google.com (mail-ig0-f172.google.com [209.85.213.172]) by aserp1020.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5RIh4Ac025900 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 27 Jun 2014 18:43:04 GMT Authentication-Results: aserp1020.oracle.com; dkim=pass reason="2048-bit key" header.d=gmail.com header.i=@gmail.com header.b=b2Ox2vMX Received: by mail-ig0-f172.google.com with SMTP id hn18so2300219igb.11 for ; Fri, 27 Jun 2014 11:43:04 -0700 (PDT) X-Received: by 10.50.147.3 with SMTP id tg3mr7956393igb.24.1403894584211; Fri, 27 Jun 2014 11:43:04 -0700 (PDT) Received: from seurat.1015granger.net ([2604:8800:100:81fc:20c:29ff:fe44:ec31]) by mx.google.com with ESMTPSA id uu8sm15756642igb.13.2014.06.27.11.43.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Jun 2014 11:43:03 -0700 (PDT) To: fedfs-utils-devel@oss.oracle.com From: Chuck Lever Date: Fri, 27 Jun 2014 14:43:03 -0400 Message-ID: <20140627184302.52216.96952.stgit@seurat.1015granger.net> In-Reply-To: <20140627184201.52216.94080.stgit@seurat.1015granger.net> References: <20140627184201.52216.94080.stgit@seurat.1015granger.net> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Flow-Control-Info: class=Pass-to-MM reputation=ipRisk-All ip=209.85.213.172 ct-class=R5 ct-vol1=-91 ct-vol2=8 ct-vol3=7 ct-risk=40 ct-spam1=59 ct-spam2=7 ct-bulk=6 rcpts=1 size=2196 X-Sendmail-CM-Score: 0.00% X-Sendmail-CM-Analysis: v=2.1 cv=Gd8uw2nL c=1 sm=1 tr=0 a=0T8DnW5xlUJKQG3F+FVMbQ==:117 a=dzsqy3y4QnMA:10 a=t5mc_itOYAkA:10 a=dPGociXpb70A:10 a=IkcTkHD0fZMA:10 a=xqWC_Br6kY4A:10 a=yPCof4ZbAAAA:8 a=Lb1rMZzfAAAA:8 a=1XWaLZrsAAAA:8 a=yyhWWOt28tg_B2hVVJsA:9 a=QEXdDO 2ut3YA:10 a=7DSvI1NPTFQA:10 X-Sendmail-CT-RefID: str=0001.0A090202.53ADBB39.002A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-Sendmail-CT-Classification: not spam Subject: [fedfs-utils] [PATCH 6/9] libnsdb: Fix NUL-termination logic in nsdb_set_parentdir() X-BeenThere: fedfs-utils-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list Reply-To: fedfs-utils Developers List-Id: fedfs-utils Developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: fedfs-utils-devel-bounces@oss.oracle.com Errors-To: fedfs-utils-devel-bounces@oss.oracle.com X-Source-IP: acsinet21.oracle.com [141.146.126.237] Ensure that pathname buffers have space for the NUL terminator. Note this function is currently unused. Fixes: 0520ee72 (Initial commit) Signed-off-by: Chuck Lever --- src/libnsdb/nsdb.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libnsdb/nsdb.c b/src/libnsdb/nsdb.c index 41d0e9e2b2a7..f4adc72074b4 100644 --- a/src/libnsdb/nsdb.c +++ b/src/libnsdb/nsdb.c @@ -95,7 +95,7 @@ static char fedfs_nsdbcerts_dirname[PATH_MAX + 1] = /** * Stores pathname of database containing FedFS persistent state */ -static char fedfs_db_filename[PATH_MAX] = +static char fedfs_db_filename[PATH_MAX + 1] = FEDFS_DEFAULT_STATEDIR "/" FEDFS_DATABASE_FILE; /** @@ -110,15 +110,23 @@ static char fedfs_db_filename[PATH_MAX] = _Bool nsdb_set_parentdir(const char *parentdir) { - static char buf[PATH_MAX]; + static char buf[PATH_MAX + 1]; struct stat st; char *path; int len; + if (parentdir == NULL) { + xlog(D_GENERAL, "%s: Passed a NULL argument", __func__); + return false; + } + if (strlen(parentdir) > PATH_MAX) { + xlog(D_GENERAL, "%s: Argument too long", __func__); + return false; + } + xlog(D_CALL, "%s: Setting up %s as our FedFS state directory", __func__, parentdir); - /* First: test length of name and whether it exists */ if (lstat(parentdir, &st) == -1) { xlog(D_GENERAL, "%s: Failed to stat %s: %m", __func__, parentdir); @@ -129,12 +137,10 @@ nsdb_set_parentdir(const char *parentdir) __func__, parentdir); return false; } - - /* Ensure we have a clean directory pathname */ - strncpy(buf, parentdir, sizeof(buf)); + strcpy(buf, parentdir); path = dirname(buf); if (*path == '.') { - xlog(D_GENERAL, "%s: Unusable pathname %s", + xlog(D_GENERAL, "%s: Pathname %s is relative", __func__, parentdir); return false; } @@ -154,9 +160,7 @@ nsdb_set_parentdir(const char *parentdir) return false; } strcpy(fedfs_nsdbcerts_dirname, buf); - - strncpy(fedfs_base_dirname, parentdir, sizeof(fedfs_base_dirname)); - + strcpy(fedfs_base_dirname, parentdir); return true; }