summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2004-01-12 04:22:24 +0000
committerBob Beck <beck@cvs.openbsd.org>2004-01-12 04:22:24 +0000
commit9cc7395a6ca9e36e4ac79b582068b1938837b7af (patch)
tree629ee6ecc621aab98c957878d032306b627ab004
parentbe8035e0f8bf61442066651cdb3ab65ecdce4e7c (diff)
fix string mishandling of lpath, ok millert, deraadt
-rw-r--r--usr.bin/sup/src/scm.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/usr.bin/sup/src/scm.c b/usr.bin/sup/src/scm.c
index 16b98a3bba6..61a8f0990d8 100644
--- a/usr.bin/sup/src/scm.c
+++ b/usr.bin/sup/src/scm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scm.c,v 1.16 2002/06/12 06:07:16 mpech Exp $ */
+/* $OpenBSD: scm.c,v 1.17 2004/01/12 04:22:23 beck Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -235,7 +235,7 @@ lock_host_file(lockdir)
char *lockdir;
{
char *dd, *lpath;
- int i, fd;
+ int fd;
FILE *f;
dd = strdup(inet_ntoa(remoteaddr));
@@ -243,22 +243,11 @@ lock_host_file(lockdir)
syslog(LOG_ERR, "Malloc failed in lock_host_file()");
return(-1);
}
- i = strlen(lockdir) + strlen(dd) + 2; /* NUL and maybe a / */
- lpath = (char *)malloc(i);
- if (lpath == NULL) {
+ if (asprintf(&lpath, "%s/%s", lockdir, dd) == -1) {
syslog(LOG_ERR, "Malloc failed in lock_host_file()");
free(dd);
return(-1);
}
- (void) strlcpy(lpath, lockdir, i);
- if (lpath[strlen(lpath) - 1] != '/') {
- lpath[strlen(lpath)] = '/';
- lpath[strlen(lpath) + 1] = '\0';
- }
- if (strlcat(lpath, dd, i) >= i) {
- syslog(LOG_CRIT, "Buffer overrun in lock_host_file(). SHOULD NOT HAPPEN!");
- abort();
- }
free(dd);
if ((fd = open(lpath, O_CREAT | O_WRONLY, 0600)) < 0) {
syslog(LOG_ERR, "Couldn't open/create lock file %s (%m)", lpath);