From 4dedca9fd7ce4e8a3d1e1c041bc7fb5af2522cc7 Mon Sep 17 00:00:00 2001 From: Kris Kennaway Date: Fri, 19 Jan 2001 23:11:18 +0000 Subject: [PATCH] Prevent overflow in -d argument by replacing hand-rolled strcat+strcpy+perror with err() Submitted by: Mike Heffner --- usr.sbin/pcvt/cursor/cursor.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/usr.sbin/pcvt/cursor/cursor.c b/usr.sbin/pcvt/cursor/cursor.c index 2798f57267d..01bdd102b37 100644 --- a/usr.sbin/pcvt/cursor/cursor.c +++ b/usr.sbin/pcvt/cursor/cursor.c @@ -45,6 +45,7 @@ static char *id = *---------------------------------------------------------------------------*/ #include +#include #include #include #include @@ -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); }