about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-01 00:04:43 -0400
committerJune McEnroe <june@causal.agency>2020-08-01 00:04:43 -0400
commitf4cb4cdf2ebf630ccb9d41f5ebabdf75a9a989e8 (patch)
tree88d7204adf656791e35d98efc2e6c341f35dd46a
parentUse snprintf instead of strlcpy (diff)
downloadpounce-f4cb4cdf2ebf630ccb9d41f5ebabdf75a9a989e8.tar.gz
pounce-f4cb4cdf2ebf630ccb9d41f5ebabdf75a9a989e8.zip
Use snprintf instead of strlcat
Diffstat (limited to '')
-rw-r--r--bounce.c4
-rw-r--r--bounce.h15
-rw-r--r--compat.h3
3 files changed, 11 insertions, 11 deletions
diff --git a/bounce.c b/bounce.c
index bee8aca..fc820a3 100644
--- a/bounce.c
+++ b/bounce.c
@@ -392,8 +392,8 @@ int main(int argc, char *argv[]) {
 		int error = stat(bindPath, &st);
 		if (error && errno != ENOENT) err(EX_CANTCREAT, "%s", bindPath);
 		if (S_ISDIR(st.st_mode)) {
-			strlcat(bindPath, "/", sizeof(bindPath));
-			strlcat(bindPath, bindHost, sizeof(bindPath));
+			size_t len = strlen(bindPath);
+			snprintf(&bindPath[len], sizeof(bindPath) - len, "/%s", bindHost);
 		}
 	}
 	if (!certPath[0]) {
diff --git a/bounce.h b/bounce.h
index 050d818..21a1d4e 100644
--- a/bounce.h
+++ b/bounce.h
@@ -138,14 +138,17 @@ static inline enum Cap capParse(const char *list, const char *values[CapBits]) {
 static inline const char *capList(enum Cap caps, const char *values[CapBits]) {
 	static char buf[1024];
 	buf[0] = '\0';
+	size_t len = 0;
 	for (size_t i = 0; i < ARRAY_LEN(CapNames); ++i) {
 		if (caps & (1 << i)) {
-			if (buf[0]) strlcat(buf, " ", sizeof(buf));
-			strlcat(buf, CapNames[i], sizeof(buf));
-			if (values && values[i]) {
-				strlcat(buf, "=", sizeof(buf));
-				strlcat(buf, values[i], sizeof(buf));
-			}
+			len += snprintf(
+				&buf[len], sizeof(buf) - len,
+				"%s%s%s%s",
+				(len ? " " : ""), CapNames[i],
+				(values && values[i] ? "=" : ""),
+				(values && values[i] ? values[i] : "")
+			);
+			if (len >= sizeof(buf)) break;
 		}
 	}
 	return buf;
diff --git a/compat.h b/compat.h
index 4559434..9675320 100644
--- a/compat.h
+++ b/compat.h
@@ -30,9 +30,6 @@
 
 // libcrypto defines these functions if libc doesn't.
 void explicit_bzero(void *b, size_t len);
-#ifndef strlcat
-size_t strlcat(char *restrict dst, const char *restrict src, size_t dstsize);
-#endif
 
 #ifndef SIGINFO
 #define SIGINFO SIGUSR2