[BugFix] pathfuncs.c path_append_ex basepath_max might cause buffer ovfl

strlcpy returns the length of the string that would have been copied
had there been sufficient space basepath_max might still be
larger than buf_size yet smaller than len
which would result in a null terminator being written past buf[buf_size-1]

Change-Id: I43e8ba9f72ea35bfe4f759ecd102c2e4bd26eb75
This commit is contained in:
William Wilgus 2024-12-30 19:16:46 -05:00
parent 27aff7ec8d
commit 186ad1234b

View file

@ -570,7 +570,7 @@ size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max,
if (basepath_max < len) /*if needed truncate basepath to basepath_max */ if (basepath_max < len) /*if needed truncate basepath to basepath_max */
{ {
len = basepath_max; len = basepath_max;
buf[basepath_max] = '\0'; buf[MIN(bufsize - 1, basepath_max)] = '\0';
} }
} }