Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jun 2015 21:55:55 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r284582 - in head: sys/geom/label usr.sbin/fstyp
Message-ID:  <201506182155.t5ILttwm068873@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Thu Jun 18 21:55:55 2015
New Revision: 284582
URL: https://svnweb.freebsd.org/changeset/base/284582

Log:
  Fix off-by-one error in fstyp(8) and geom_label(4) that made them use
  a single space (" ") as a CD9660 label name when no label was present.
  Similar problem was also present in msdosfs label recognition.
  
  PR:		200828
  Differential Revision:	https://reviews.freebsd.org/D2830
  Reviewed by:	asomers@, emaste@
  MFC after:	2 weeks
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/geom/label/g_label.c
  head/sys/geom/label/g_label.h
  head/sys/geom/label/g_label_iso9660.c
  head/sys/geom/label/g_label_msdosfs.c
  head/usr.sbin/fstyp/cd9660.c
  head/usr.sbin/fstyp/fstyp.c
  head/usr.sbin/fstyp/fstyp.h
  head/usr.sbin/fstyp/msdosfs.c

Modified: head/sys/geom/label/g_label.c
==============================================================================
--- head/sys/geom/label/g_label.c	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/sys/geom/label/g_label.c	Thu Jun 18 21:55:55 2015	(r284582)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/libkern.h>
 #include <sys/sbuf.h>
+#include <sys/stddef.h>
 #include <sys/sysctl.h>
 #include <geom/geom.h>
 #include <geom/geom_slice.h>
@@ -96,6 +97,20 @@ const struct g_label_desc *g_labels[] = 
 	NULL
 };
 
+void
+g_label_rtrim(char *label, size_t size)
+{
+	ptrdiff_t i;
+
+	for (i = size - 1; i >= 0; i--) {
+		if (label[i] == '\0')
+			continue;
+		else if (label[i] == ' ')
+			label[i] = '\0';
+		else
+			break;
+	}
+}
 
 static int
 g_label_destroy_geom(struct gctl_req *req __unused, struct g_class *mp,

Modified: head/sys/geom/label/g_label.h
==============================================================================
--- head/sys/geom/label/g_label.h	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/sys/geom/label/g_label.h	Thu Jun 18 21:55:55 2015	(r284582)
@@ -86,6 +86,8 @@ extern struct g_label_desc g_label_ntfs;
 extern struct g_label_desc g_label_gpt;
 extern struct g_label_desc g_label_gpt_uuid;
 extern struct g_label_desc g_label_disk_ident;
+
+extern void g_label_rtrim(char *label, size_t size);
 #endif	/* _KERNEL */
 
 struct g_label_metadata {

Modified: head/sys/geom/label/g_label_iso9660.c
==============================================================================
--- head/sys/geom/label/g_label_iso9660.c	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/sys/geom/label/g_label_iso9660.c	Thu Jun 18 21:55:55 2015	(r284582)
@@ -47,7 +47,6 @@ g_label_iso9660_taste(struct g_consumer 
 {
 	struct g_provider *pp;
 	char *sector, *volume;
-	int i;
 
 	g_topology_assert_not();
 	pp = cp->provider;
@@ -68,14 +67,7 @@ g_label_iso9660_taste(struct g_consumer 
 	bzero(label, size);
 	strlcpy(label, volume, MIN(size, VOLUME_LEN));
 	g_free(sector);
-	for (i = size - 1; i > 0; i--) {
-		if (label[i] == '\0')
-			continue;
-		else if (label[i] == ' ')
-			label[i] = '\0';
-		else
-			break;
-	}
+	g_label_rtrim(label, size);
 }
 
 struct g_label_desc g_label_iso9660 = {

Modified: head/sys/geom/label/g_label_msdosfs.c
==============================================================================
--- head/sys/geom/label/g_label_msdosfs.c	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/sys/geom/label/g_label_msdosfs.c	Thu Jun 18 21:55:55 2015	(r284582)
@@ -48,7 +48,6 @@ g_label_msdosfs_taste(struct g_consumer 
 	FAT32_BSBPB *pfat32_bsbpb;
 	FAT_DES *pfat_entry;
 	uint8_t *sector0, *sector;
-	uint32_t i;
 
 	g_topology_assert_not();
 	pp = cp->provider;
@@ -200,14 +199,7 @@ g_label_msdosfs_taste(struct g_consumer 
 	}
 
 endofchecks:
-	for (i = size - 1; i > 0; i--) {
-		if (label[i] == '\0')
-			continue;
-		else if (label[i] == ' ')
-			label[i] = '\0';
-		else
-			break;
-	}
+	g_label_rtrim(label, size);
 
 error:
 	if (sector0 != NULL)

Modified: head/usr.sbin/fstyp/cd9660.c
==============================================================================
--- head/usr.sbin/fstyp/cd9660.c	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/usr.sbin/fstyp/cd9660.c	Thu Jun 18 21:55:55 2015	(r284582)
@@ -45,7 +45,6 @@ int
 fstyp_cd9660(FILE *fp, char *label, size_t size)
 {
 	char *sector, *volume;
-	int i;
 
 	sector = read_buf(fp, ISO9660_OFFSET, 512);
 	if (sector == NULL)
@@ -58,13 +57,6 @@ fstyp_cd9660(FILE *fp, char *label, size
 	bzero(label, size);
 	strlcpy(label, volume, MIN(size, VOLUME_LEN));
 	free(sector);
-	for (i = size - 1; i > 0; i--) {
-		if (label[i] == '\0')
-			continue;
-		else if (label[i] == ' ')
-			label[i] = '\0';
-		else
-			break;
-	}
+	rtrim(label, size);
 	return (0);
 }

Modified: head/usr.sbin/fstyp/fstyp.c
==============================================================================
--- head/usr.sbin/fstyp/fstyp.c	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/usr.sbin/fstyp/fstyp.c	Thu Jun 18 21:55:55 2015	(r284582)
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
 #include <err.h>
 #include <errno.h>
 #include <stdbool.h>
+#include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -104,6 +105,21 @@ checked_strdup(const char *s)
 	return (c);
 }
 
+void
+rtrim(char *label, size_t size)
+{
+	ptrdiff_t i;
+
+	for (i = size - 1; i >= 0; i--) {
+		if (label[i] == '\0')
+			continue;
+		else if (label[i] == ' ')
+			label[i] = '\0';
+		else
+			break;
+	}
+}
+
 static void
 usage(void)
 {

Modified: head/usr.sbin/fstyp/fstyp.h
==============================================================================
--- head/usr.sbin/fstyp/fstyp.h	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/usr.sbin/fstyp/fstyp.h	Thu Jun 18 21:55:55 2015	(r284582)
@@ -36,6 +36,7 @@
 
 void	*read_buf(FILE *fp, off_t off, size_t len);
 char	*checked_strdup(const char *s);
+void	rtrim(char *label, size_t size);
 
 int	fstyp_cd9660(FILE *fp, char *label, size_t size);
 int	fstyp_ext2fs(FILE *fp, char *label, size_t size);

Modified: head/usr.sbin/fstyp/msdosfs.c
==============================================================================
--- head/usr.sbin/fstyp/msdosfs.c	Thu Jun 18 21:25:07 2015	(r284581)
+++ head/usr.sbin/fstyp/msdosfs.c	Thu Jun 18 21:55:55 2015	(r284582)
@@ -48,7 +48,6 @@ fstyp_msdosfs(FILE *fp, char *label, siz
 	FAT32_BSBPB *pfat32_bsbpb;
 	FAT_DES *pfat_entry;
 	uint8_t *sector0, *sector;
-	uint32_t i;
 
 	sector0 = NULL;
 	sector = NULL;
@@ -161,14 +160,7 @@ fstyp_msdosfs(FILE *fp, char *label, siz
 	}
 
 endofchecks:
-	for (i = size - 1; i > 0; i--) {
-		if (label[i] == '\0')
-			continue;
-		else if (label[i] == ' ')
-			label[i] = '\0';
-		else
-			break;
-	}
+	rtrim(label, size);
 
 	free(sector0);
 	free(sector);



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