Skip to content

Commit 69f7799

Browse files
ejohnstownpadelsbach
authored andcommitted
Check Include path truncation in sshd config
HandleInclude built the wildcard include path with WSNPRINTF without checking the result, silently truncating over-long paths (flagged by GCC 12 as -Werror=format-truncation). Merge the duplicate WSNPRINTF calls and return WS_INVALID_PATH_E when the path does not fit.
1 parent 92e1bdc commit 69f7799

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

apps/wolfsshd/configuration.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -798,18 +798,17 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value, int depth)
798798
WSTRLEN(fileNames[i]) -
799799
WSTRLEN(postfix),
800800
postfix, WSTRLEN(postfix))
801-
== 0) {
802-
WSNPRINTF(filepath, PATH_MAX, "%s/%s", path,
803-
fileNames[i]);
804-
}
805-
else {
801+
!= 0) {
806802
/* Not a match */
807803
continue;
808804
}
809805
}
810-
else {
811-
WSNPRINTF(filepath, PATH_MAX, "%s/%s", path,
812-
fileNames[i]);
806+
ret = WSNPRINTF(filepath, PATH_MAX, "%s/%s", path,
807+
fileNames[i]);
808+
if (ret < 0 || ret >= PATH_MAX) {
809+
/* Path is too long for the buffer */
810+
ret = WS_INVALID_PATH_E;
811+
break;
813812
}
814813
ret = ConfigLoad(conf, filepath, depth);
815814
if (ret != WS_SUCCESS) {

0 commit comments

Comments
 (0)