aboutsummaryrefslogtreecommitdiff
path: root/sbin/bsdlabel/bsdlabel.c
diff options
context:
space:
mode:
authorJaakko Heinonen <jh@FreeBSD.org>2010-08-15 17:49:41 +0000
committerJaakko Heinonen <jh@FreeBSD.org>2010-08-15 17:49:41 +0000
commitfb26ece72cb35fe66683f57ea3e776a203c407fc (patch)
treebf77610e1bb8fbb161cf919262392b1bcb302809 /sbin/bsdlabel/bsdlabel.c
parenta129ce01677fed0df25a93bad9702a5fcde3c36b (diff)
downloadsrc-fb26ece72cb35fe66683f57ea3e776a203c407fc.tar.gz
src-fb26ece72cb35fe66683f57ea3e776a203c407fc.zip
- 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
Notes
Notes: svn path=/head/; revision=211342
Diffstat (limited to 'sbin/bsdlabel/bsdlabel.c')
-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 b34fe75d0758..fb1d8b0d86e1 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,