summaryrefslogtreecommitdiffstats
path: root/lib/libutil/uucplock.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1997-04-02 03:38:29 +0000
committerache <ache@FreeBSD.org>1997-04-02 03:38:29 +0000
commit3c64721fa7494c5d4170f9381313141a91458b8b (patch)
treea342976832358f8c83403ab479e866772ac07d25 /lib/libutil/uucplock.c
parente15367f402853296b0c91403b1ca75dc982eae71 (diff)
downloadFreeBSD-src-3c64721fa7494c5d4170f9381313141a91458b8b.zip
FreeBSD-src-3c64721fa7494c5d4170f9381313141a91458b8b.tar.gz
Remove unused USE_PERROR define and syslog.h include
Use snprintf instead of sprintf to avoid buffer overflows Use snprintf in uu_lockerr instead of lots of hardcoded constants and not null-terminated strncpy Return "" for OK and "device in use" for INUSE, it allows simple strcpy(buf, uu_lockerr(retcode)) without testing for special OK case (NULL was there) and obtaining meaningful result for INUSE ("" was there) without special testing for it too.
Diffstat (limited to 'lib/libutil/uucplock.c')
-rw-r--r--lib/libutil/uucplock.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/libutil/uucplock.c b/lib/libutil/uucplock.c
index 0f08646..f6af4d0 100644
--- a/lib/libutil/uucplock.c
+++ b/lib/libutil/uucplock.c
@@ -39,9 +39,6 @@ static const char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93";
#include <sys/file.h>
#include <dirent.h>
#include <errno.h>
-#ifndef USE_PERROR
-#include <syslog.h>
-#endif
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
@@ -69,7 +66,7 @@ int uu_lock (char *ttyname)
char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN];
int err;
- (void)sprintf(tbuf, _PATH_UUCPLOCK LOCKFMT, ttyname);
+ (void)snprintf(tbuf, sizeof(tbuf), _PATH_UUCPLOCK LOCKFMT, ttyname);
fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660);
if (fd < 0) {
/*
@@ -118,43 +115,41 @@ int uu_unlock (char *ttyname)
{
char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN];
- (void)sprintf(tbuf, _PATH_UUCPLOCK LOCKFMT, ttyname);
+ (void)snprintf(tbuf, sizeof(tbuf), _PATH_UUCPLOCK LOCKFMT, ttyname);
return unlink(tbuf);
}
char *uu_lockerr (int uu_lockresult)
{
static char errbuf[512];
- int len;
switch (uu_lockresult) {
case UU_LOCK_INUSE:
- return "";
+ return "device in use";
case UU_LOCK_OK:
- return 0;
+ return "";
case UU_LOCK_OPEN_ERR:
- strcpy(errbuf,"open error: ");
- len = 12;
+ (void)snprintf(errbuf, sizeof(errbuf),
+ "open error: %s", strerror(errno));
break;
case UU_LOCK_READ_ERR:
- strcpy(errbuf,"read error: ");
- len = 12;
+ (void)snprintf(errbuf, sizeof(errbuf),
+ "read error: %s", strerror(errno));
break;
case UU_LOCK_SEEK_ERR:
- strcpy(errbuf,"seek error: ");
- len = 12;
+ (void)snprintf(errbuf, sizeof(errbuf),
+ "seek error: %s", strerror(errno));
break;
case UU_LOCK_WRITE_ERR:
- strcpy(errbuf,"write error: ");
- len = 13;
+ (void)snprintf(errbuf, sizeof(errbuf),
+ "write error: %s", strerror(errno));
break;
default:
- strcpy(errbuf,"Undefined error: ");
- len = 17;
+ (void)snprintf(errbuf, sizeof(errbuf),
+ "undefined error: %s", strerror(errno));
break;
}
- strncpy(errbuf+len,strerror(errno),sizeof(errbuf)-len-1);
return errbuf;
}
OpenPOWER on IntegriCloud