Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:07:00 -0000
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r346301 - stable/12/lib/libbe
Message-ID:  <201904162059.x3GKxw2L047039@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Tue Apr 16 20:59:57 2019
New Revision: 346301
URL: https://svnweb.freebsd.org/changeset/base/346301

Log:
  MFC r346082: libbe(3): use libzfs name validation for datasets/snapshot names
  
  Our home-rolled solution didn't quite capture all of the details, and we
  didn't actually validate snapshot names at all. zfs_name_valid captures the
  important details, but it doesn't necessarily expose the errors that we're
  wanting to see in the be_validate_* functions. Validating lengths
  independently, then the names, should make this a non-issue.

Modified:
  stable/12/lib/libbe/be.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libbe/be.c
==============================================================================
--- stable/12/lib/libbe/be.c	Tue Apr 16 20:56:51 2019	(r346300)
+++ stable/12/lib/libbe/be.c	Tue Apr 16 20:59:57 2019	(r346301)
@@ -593,6 +593,9 @@ be_validate_snap(libbe_handle_t *lbh, const char *snap
 	if (strlen(snap_name) >= BE_MAXPATHLEN)
 		return (BE_ERR_PATHLEN);
 
+	if (!zfs_name_valid(snap_name, ZFS_TYPE_SNAPSHOT))
+		return (BE_ERR_INVALIDNAME);
+
 	if (!zfs_dataset_exists(lbh->lzh, snap_name,
 	    ZFS_TYPE_SNAPSHOT))
 		return (BE_ERR_NOENT);
@@ -646,12 +649,6 @@ be_root_concat(libbe_handle_t *lbh, const char *name, 
 int
 be_validate_name(libbe_handle_t *lbh, const char *name)
 {
-	for (int i = 0; *name; i++) {
-		char c = *(name++);
-		if (isalnum(c) || (c == '-') || (c == '_') || (c == '.'))
-			continue;
-		return (BE_ERR_INVALIDNAME);
-	}
 
 	/*
 	 * Impose the additional restriction that the entire dataset name must
@@ -659,6 +656,10 @@ be_validate_name(libbe_handle_t *lbh, const char *name
 	 */
 	if (strlen(lbh->root) + 1 + strlen(name) > MAXNAMELEN)
 		return (BE_ERR_PATHLEN);
+
+	if (!zfs_name_valid(name, ZFS_TYPE_DATASET))
+		return (BE_ERR_INVALIDNAME);
+
 	return (BE_ERR_SUCCESS);
 }
 





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904162059.x3GKxw2L047039>