summaryrefslogtreecommitdiffstats
path: root/usr.sbin/fstyp
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2015-08-02 10:08:57 +0000
committertrasz <trasz@FreeBSD.org>2015-08-02 10:08:57 +0000
commit75c063e8b8ed27522de533ba24a98e50a29617e6 (patch)
treefdfa2cf5f8ca6dda97dd9a21a4b61ec291b9e26e /usr.sbin/fstyp
parent529945ff14626dc8dc217b57e92818e9ab7e55f3 (diff)
downloadFreeBSD-src-75c063e8b8ed27522de533ba24a98e50a29617e6.zip
FreeBSD-src-75c063e8b8ed27522de533ba24a98e50a29617e6.tar.gz
MFC r284582:
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. Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin/fstyp')
-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 b3bdcde..b49eb1e 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