From 91471076493f87005431dd81c2bf4d0445495ca4 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Wed, 12 Jun 2024 10:46:37 -0600 Subject: Fix buffer overflow on edgecases with git repo subpaths Occasionally, a subpath will have just the right number of characters to cause a round-up, which causes a buffer overflow in the ellipt function when copying in the backend half of the string. This was causing overwrite of the branchname char 0 with `\0`, resulting in the branchname output being empty in the PS1. --- src/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index 60c6c42..8423c17 100644 --- a/src/common.c +++ b/src/common.c @@ -42,5 +42,6 @@ void ellipt(char* buf, char* outbuf, int size) { strncpy(outbuf, buf, (size/2)-3); strcat(outbuf, "..."); // Copy in the back end - strcpy(&outbuf[(size/2)], &buf[buflen - size/2]); + // NOTE: Extra +1 for rounding errors to prevent buffer overflows + strcpy(&outbuf[(size/2)], &buf[buflen - (size/2) +1]); } -- cgit v1.2.3