summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2015-06-18 21:55:55 +0000
committertrasz <trasz@FreeBSD.org>2015-06-18 21:55:55 +0000
commit19250d4f16f66aaad903ed821f23db1b699eeb83 (patch)
tree4066f81eaf35cc353c8f3611fe6de9b0fd9df77f /usr.sbin
parent37e1f5956c5d18fa0bb179ce4913b67eec397465 (diff)
downloadFreeBSD-src-19250d4f16f66aaad903ed821f23db1b699eeb83.zip
FreeBSD-src-19250d4f16f66aaad903ed821f23db1b699eeb83.tar.gz
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
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/fstyp/cd9660.c10
-rw-r--r--usr.sbin/fstyp/fstyp.c16
-rw-r--r--usr.sbin/fstyp/fstyp.h1
-rw-r--r--usr.sbin/fstyp/msdosfs.c10
4 files changed, 19 insertions, 18 deletions
diff --git a/usr.sbin/fstyp/cd9660.c b/usr.sbin/fstyp/cd9660.c
index ee6af11..658af33 100644
--- a/usr.sbin/fstyp/cd9660.c
+++ b/usr.sbin/fstyp/cd9660.c
@@ -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_t 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);
}
diff --git a/usr.sbin/fstyp/fstyp.c b/usr.sbin/fstyp/fstyp.c
index d6a48f6..1a699eb 100644
--- a/usr.sbin/fstyp/fstyp.c
+++ b/usr.sbin/fstyp/fstyp.c
@@ -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)
{
diff --git a/usr.sbin/fstyp/fstyp.h b/usr.sbin/fstyp/fstyp.h
index 4474ffe..d4fd54f 100644
--- a/usr.sbin/fstyp/fstyp.h
+++ b/usr.sbin/fstyp/fstyp.h
@@ -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);
diff --git a/usr.sbin/fstyp/msdosfs.c b/usr.sbin/fstyp/msdosfs.c
index b299243..3d86802 100644
--- a/usr.sbin/fstyp/msdosfs.c
+++ b/usr.sbin/fstyp/msdosfs.c
@@ -48,7 +48,6 @@ fstyp_msdosfs(FILE *fp, char *label, size_t size)
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, size_t size)
}
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);
OpenPOWER on IntegriCloud