mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-26 13:05:18 +01:00
Use FIODTYPE to unbogosify much of the file type checking in dd.
This commit is contained in:
parent
b5fca1cb2a
commit
e08d7384ee
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=50460
25
bin/dd/dd.c
25
bin/dd/dd.c
@ -46,12 +46,14 @@ static char const copyright[] =
|
|||||||
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"$Id: dd.c,v 1.18 1999/06/20 14:58:51 green Exp $";
|
"$Id: dd.c,v 1.19 1999/07/13 18:44:56 green Exp $";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/conf.h>
|
||||||
#include <sys/diskslice.h>
|
#include <sys/diskslice.h>
|
||||||
|
#include <sys/filio.h>
|
||||||
#include <sys/mtio.h>
|
#include <sys/mtio.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -224,19 +226,22 @@ static void
|
|||||||
getfdtype(io)
|
getfdtype(io)
|
||||||
IO *io;
|
IO *io;
|
||||||
{
|
{
|
||||||
struct mtget mt;
|
|
||||||
struct diskslices ds;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
int type;
|
||||||
|
|
||||||
if (fstat(io->fd, &sb))
|
if (fstat(io->fd, &sb))
|
||||||
err(1, "%s", io->name);
|
err(1, "%s", io->name);
|
||||||
if ((S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) &&
|
if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) {
|
||||||
ioctl(io->fd, DIOCGSLICEINFO, &ds) != -1)
|
if (ioctl(io->fd, FIODTYPE, &type) == -1)
|
||||||
io->flags |= ISDISK;
|
err(1, "%s", io->name);
|
||||||
if (S_ISCHR(sb.st_mode))
|
if (type & D_TAPE)
|
||||||
io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
|
io->flags |= ISTAPE;
|
||||||
else if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
|
else if (type & D_DISK)
|
||||||
io->flags |= ISPIPE; /* XXX fixed in 4.4BSD */
|
io->flags |= ISDISK;
|
||||||
|
if (S_ISCHR(sb.st_mode) && (type & D_TAPE) == 0)
|
||||||
|
io->flags |= ISCHR;
|
||||||
|
} else if (!S_ISREG(sb.st_mode))
|
||||||
|
io->flags |= ISPIPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user