Prevent overflow in -d argument by replacing hand-rolled

strcat+strcpy+perror with err()

Submitted by:	Mike Heffner <mheffner@vt.edu>
This commit is contained in:
kris 2001-01-19 23:11:18 +00:00
parent 371aa8fa98
commit 1e465c4703

View File

@ -45,6 +45,7 @@ static char *id =
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <err.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <machine/pcvt_ioctl.h>
@ -101,31 +102,15 @@ char *argv[];
{
fd = DEFAULTFD;
}
else
{
if((fd = open(device, O_RDWR)) == -1)
{
char buffer[80];
strcpy(buffer,"ERROR opening ");
strcat(buffer,device);
perror(buffer);
exit(1);
}
}
else if((fd = open(device, O_RDWR)) == -1)
err(1, "ERROR opening %s", device);
if(screen == -1)
{
struct stat stat;
if((fstat(fd, &stat)) == -1)
{
char buffer[80];
strcpy(buffer,"ERROR opening ");
strcat(buffer,device);
perror(buffer);
exit(1);
}
err(1, "ERROR opening %s", device);
screen = minor(stat.st_rdev);
}
@ -134,10 +119,7 @@ char *argv[];
cursorshape.screen_no = screen;
if(ioctl(fd, VGACURSOR, &cursorshape) == -1)
{
perror("cursor - ioctl VGACURSOR failed, error");
exit(1);
}
err(1, "cursor - ioctl VGACURSOR failed, error");
else
exit(0);
}