diff options
author | 2004-01-12 04:22:23 +0000 | |
---|---|---|
committer | 2004-01-12 04:22:23 +0000 | |
commit | 6375083a95ffebbe03d60a0d534f178c9b0499de (patch) | |
tree | 968f7f00cad314cb2dbb2c1be357045b1c45318b | |
parent | some comments on ffs sysctls, mainly dirhash (diff) | |
download | wireguard-openbsd-6375083a95ffebbe03d60a0d534f178c9b0499de.tar.xz wireguard-openbsd-6375083a95ffebbe03d60a0d534f178c9b0499de.zip |
fix string mishandling of lpath, ok millert, deraadt
-rw-r--r-- | usr.bin/sup/src/scm.c | 17 |
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); |