summaryrefslogtreecommitdiffstats
path: root/sbin/bsdlabel
diff options
context:
space:
mode:
authorjh <jh@FreeBSD.org>2010-08-15 17:49:41 +0000
committerjh <jh@FreeBSD.org>2010-08-15 17:49:41 +0000
commitf407cc3b8bf18a19de0375c20d6ab712bab4f21d (patch)
treebf77610e1bb8fbb161cf919262392b1bcb302809 /sbin/bsdlabel
parent072152a8c4a43f3a4a7b55b59307758687c869d3 (diff)
downloadFreeBSD-src-f407cc3b8bf18a19de0375c20d6ab712bab4f21d.zip
FreeBSD-src-f407cc3b8bf18a19de0375c20d6ab712bab4f21d.tar.gz
- Check that strtoul(3) succeeds to convert the entire string in a few
places. - In getasciilabel(), set the disk type only when a valid type is given. PR: bin/86765 MFC after: 2 weeks
Diffstat (limited to 'sbin/bsdlabel')
-rw-r--r--sbin/bsdlabel/bsdlabel.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c
index b34fe75..fb1d8b0 100644
--- a/sbin/bsdlabel/bsdlabel.c
+++ b/sbin/bsdlabel/bsdlabel.c
@@ -755,7 +755,7 @@ word(char *cp)
static int
getasciilabel(FILE *f, struct disklabel *lp)
{
- char *cp;
+ char *cp, *endp;
const char **cpp;
u_int part;
char *tp, line[BUFSIZ];
@@ -794,11 +794,15 @@ getasciilabel(FILE *f, struct disklabel *lp)
}
if (cpp < &dktypenames[DKMAXTYPES])
continue;
- v = strtoul(tp, NULL, 10);
+ errno = 0;
+ v = strtoul(tp, &endp, 10);
+ if (errno != 0 || *endp != '\0')
+ v = DKMAXTYPES;
if (v >= DKMAXTYPES)
fprintf(stderr, "line %d:%s %lu\n", lineno,
"Warning, unknown disk type", v);
- lp->d_type = v;
+ else
+ lp->d_type = v;
continue;
}
if (!strcmp(cp, "flags")) {
@@ -1023,7 +1027,7 @@ static int
getasciipartspec(char *tp, struct disklabel *lp, int part, int lineno)
{
struct partition *pp;
- char *cp;
+ char *cp, *endp;
const char **cpp;
u_long v;
@@ -1059,9 +1063,12 @@ getasciipartspec(char *tp, struct disklabel *lp, int part, int lineno)
if (*cpp != NULL) {
pp->p_fstype = cpp - fstypenames;
} else {
- if (isdigit(*cp))
- v = strtoul(cp, NULL, 10);
- else
+ if (isdigit(*cp)) {
+ errno = 0;
+ v = strtoul(cp, &endp, 10);
+ if (errno != 0 || *endp != '\0')
+ v = FSMAXTYPES;
+ } else
v = FSMAXTYPES;
if (v >= FSMAXTYPES) {
fprintf(stderr,
OpenPOWER on IntegriCloud