Commit Diff


commit - 95107ed63ef4d41e6a41cb8ea2375798c9248a58
commit + ebdec4bcefe286c6b322bf26aa48b32aac6b57e5
blob - 321cb87f0d2e4e5a7c1bdb959114e3f16b9cce13
blob + e807deced49d9dc7a9acd530de7c1106944da792
--- FICS/build.mk
+++ FICS/build.mk
@@ -18,6 +18,7 @@ OBJS = $(SRC_DIR)adminproc.o\
 	$(SRC_DIR)legal.o\
 	$(SRC_DIR)lists.o\
 	$(SRC_DIR)matchproc.o\
+	$(SRC_DIR)maxxes-utils.o\
 	$(SRC_DIR)movecheck.o\
 	$(SRC_DIR)multicol.o\
 	$(SRC_DIR)network.o\
blob - /dev/null
blob + 7db8369634b89d26ea62a1bdd3bc1e28829b88d1 (mode 644)
--- /dev/null
+++ FICS/maxxes-utils.c
@@ -0,0 +1,46 @@
+// SPDX-FileCopyrightText: 2024 Markus Uhlin <maxxe@rpblc.net>
+// SPDX-License-Identifier: ISC
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#if __linux__
+#include <bsd/string.h>
+#endif
+
+#include "maxxes-utils.h"
+
+void
+snprintf_trunc_chk(const char *file, const long int line,
+    char *str, size_t size, const char *format, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, format);
+	ret = vsnprintf(str, size, format, ap);
+	va_end(ap);
+
+	if (ret < 0 || (size_t)ret >= size)
+		warnx("%s:%ld: warning: vsnprintf() truncated", file, line);
+}
+
+void
+strlcpy_trunc_chk(char *dst, const char *src, size_t dstsize,
+    const char *file,
+    const long int line)
+{
+	if (strlcpy(dst, src, dstsize) >= dstsize)
+		warnx("%s:%ld: warning: strlcpy() truncated", file, line);
+}
+
+void
+strlcat_trunc_chk(char *dst, const char *src, size_t dstsize,
+    const char *file,
+    const long int line)
+{
+	if (strlcat(dst, src, dstsize) >= dstsize)
+		warnx("%s:%ld: warning: strlcat() truncated", file, line);
+}
blob - /dev/null
blob + 667151fa509c706dbe9204df77052c8656f37e92 (mode 644)
--- /dev/null
+++ FICS/maxxes-utils.h
@@ -0,0 +1,22 @@
+#ifndef MAXXES_UTILITIES_H
+#define MAXXES_UTILITIES_H
+
+#include <stddef.h>
+
+#include "common.h"
+
+#define msnprintf(p_str, p_size, ...) \
+	snprintf_trunc_chk(__FILE__, __LINE__, (p_str), (p_size), __VA_ARGS__)
+#define mstrlcpy(p_dst, p_src, p_dstsize) \
+	strlcpy_trunc_chk((p_dst), (p_src), (p_dstsize), __FILE__, __LINE__)
+#define mstrlcat(p_dst, p_src, p_dstsize) \
+	strlcat_trunc_chk((p_dst), (p_src), (p_dstsize), __FILE__, __LINE__)
+
+void	snprintf_trunc_chk(const char *file, const long int line,
+	    char *str, size_t size, const char *format, ...) PRINTFLIKE(5);
+void	strlcpy_trunc_chk(char *dst, const char *src, size_t dstsize,
+	    const char *, const long int);
+void	strlcat_trunc_chk(char *dst, const char *src, size_t dstsize,
+	    const char *, const long int);
+
+#endif