diff options
author | Aaron Ball <nullspoon@oper.io> | 2024-06-12 10:46:37 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2024-06-12 10:46:37 -0600 |
commit | 91471076493f87005431dd81c2bf4d0445495ca4 (patch) | |
tree | dd0c81882e47d5ca6ea9391157364b9a014f1291 | |
parent | 3cc711f5df8151a631090384e4dcf9c244f38093 (diff) | |
download | nullprompt-91471076493f87005431dd81c2bf4d0445495ca4.tar.gz nullprompt-91471076493f87005431dd81c2bf4d0445495ca4.tar.xz |
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.
-rw-r--r-- | src/common.c | 3 |
1 files changed, 2 insertions, 1 deletions
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]); } |