1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-29 08:08:37 +00:00

- 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
This commit is contained in:
Jaakko Heinonen 2010-08-15 17:49:41 +00:00
parent a129ce0167
commit fb26ece72c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211342

View File

@ -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,