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.
This commit is contained in:
Andrey A. Chernov 1997-04-02 03:38:29 +00:00
parent 938401213d
commit 2875419215
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=24529
2 changed files with 17 additions and 25 deletions

View File

@ -23,7 +23,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: uucplock.3,v 1.2 1997/03/31 22:47:53 brian Exp $
.\" $Id: uucplock.3,v 1.3 1997/04/01 17:44:31 mpp Exp $
.\" "
.Dd March 30, 1997
.Os
@ -113,11 +113,8 @@ If a value of
.Dv UU_LOCK_OK
is passed to
.Fn uu_lockerr ,
a
.Dv NULL
pointer is returned. If a value of
.Dv UU_LOCK_INUSE
is passed, an empty string is returned. Otherwise, a string specifying
an empty string returned.
Otherwise, a string specifying
the reason for failure is returned.
.Fn uu_lockerr
uses the current value of

View File

@ -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;
}