mirror of
https://github.com/freebsd/freebsd-src
synced 2024-11-05 18:22:52 +00:00
Fixed printing of and comparison with d_typename[]. It is not always
null terminated.
This commit is contained in:
parent
f073fe0e04
commit
760cf7b24a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=31685
1 changed files with 8 additions and 5 deletions
|
@ -42,7 +42,7 @@ static const char copyright[] =
|
|||
static char sccsid[] = "@(#)bad144.c 8.2 (Berkeley) 4/27/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: bad144.c,v 1.15 1997/12/11 07:27:06 bde Exp $";
|
||||
"$Id: bad144.c,v 1.16 1997/12/12 17:58:31 bde Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -332,8 +332,9 @@ main(argc, argv)
|
|||
sn = atoi(*argv++);
|
||||
argc--;
|
||||
if (sn < 0 || sn >= bend) {
|
||||
printf("%d: out of range [0,%d) for disk %s\n",
|
||||
sn, bend, dp->d_typename);
|
||||
printf("%d: out of range [0,%d) for disk %.*s\n",
|
||||
sn, bend, (int)sizeof(dp->d_typename),
|
||||
dp->d_typename);
|
||||
errs++;
|
||||
continue;
|
||||
}
|
||||
|
@ -703,10 +704,12 @@ format(fd, blk)
|
|||
int n;
|
||||
|
||||
for (fp = formats; fp->f_name; fp++)
|
||||
if (strcmp(dp->d_typename, fp->f_name) == 0)
|
||||
if (strncmp(dp->d_typename, fp->f_name, sizeof(dp->d_typename))
|
||||
== 0 && strlen(fp->f_name) <= sizeof(dp->d_typename))
|
||||
break;
|
||||
if (fp->f_name == 0)
|
||||
errx(2, "don't know how to format %s disks", dp->d_typename);
|
||||
errx(2, "don't know how to format %.*s disks",
|
||||
(int)sizeof(dp->d_typename), dp->d_typename);
|
||||
if (buf && bufsize < fp->f_bufsize) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
|
|
Loading…
Reference in a new issue