about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-06-09 14:34:57 -0700
committerJune McEnroe <june@causal.agency>2021-06-09 17:54:26 -0400
commit0a1cfca0f41ca4ee5d981253b8f151c67aacf4f6 (patch)
treea3876a6d59daf3d0ad25832c79b9645d5fc88aa7
parentRemove catf (diff)
downloadcatgirl-0a1cfca0f41ca4ee5d981253b8f151c67aacf4f6.tar.gz
catgirl-0a1cfca0f41ca4ee5d981253b8f151c67aacf4f6.zip
Avoid creating out-of-bounds pointer when checking for seprintf truncation
It is technically undefined behavior (see C11 6.5.6p8) to construct
a pointer more than one past the end of an array. To prevent this,
compare n with the remaining space in the array before adding to
ptr.
-rw-r--r--chat.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/chat.h b/chat.h
index e75112a..327262b 100644
--- a/chat.h
+++ b/chat.h
@@ -52,8 +52,8 @@ static inline char *seprintf(char *ptr, char *end, const char *fmt, ...) {
 	int n = vsnprintf(ptr, end - ptr, fmt, ap);
 	va_end(ap);
 	if (n < 0) return NULL;
-	ptr += n;
-	return (ptr > end ? end : ptr);
+	if (n > end - ptr) return end;
+	return ptr + n;
 }
 
 enum Attr {
mit/index.html?id=9a27e1fb708e5c31aa7d3dc8a57f07251bc3792a&follow=1'>Reformat index.html with explore linkJune McEnroe 2019-01-16Return false from keydown handler in exploreJune McEnroe 2019-01-08Draw lines to tile edgeJune McEnroe 2019-01-08Factor out default pathsJune McEnroe 2019-01-08Remove incorrect default coordinatesJune McEnroe 2019-01-07Set img src when explore fragment changesJune McEnroe 2019-01-07Compress PNG data in imageJune McEnroe 2019-01-07madvise MADV_NOCORE in imageJune McEnroe 2019-01-07Add license notice to explore JavaScriptJune McEnroe 2019-01-07Add Q/Home binding in exploreJune McEnroe 2019-01-07Fix explore image URLJune McEnroe 2019-01-07Add HOME button, ssh link, AGPL notice to exploreJune McEnroe 2019-01-06Add meta viewport to exploreJune McEnroe 2019-01-06Set background and max-width in exploreJune McEnroe 2019-01-06Swallow writes after the connection is closedJune McEnroe 2019-01-06Handle KCGI_HUPJune McEnroe 2019-01-06Install html filesJune McEnroe