@@ -723,7 +723,7 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value, int depth)
723723
724724 if (ret == WS_SUCCESS ) {
725725 if (!WOPENDIR (NULL , conf -> heap , & d , path )) {
726- word32 fileCount = 0 , i , j ;
726+ word32 fileCount = 0 , fileFilled = 0 , i , j ;
727727 char * * fileNames = NULL ;
728728
729729 /* Count up the number of files */
@@ -749,6 +749,12 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value, int depth)
749749 if (fileNames == NULL ) {
750750 ret = WS_MEMORY_E ;
751751 }
752+ else {
753+ /* Zero so any slot not filled by the second pass
754+ * (e.g. files removed from the directory between
755+ * the two passes) is NULL rather than garbage. */
756+ WMEMSET (fileNames , 0 , fileCount * sizeof (char * ));
757+ }
752758 }
753759
754760 if (ret == WS_SUCCESS ) {
@@ -777,8 +783,12 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value, int depth)
777783 i ++ ;
778784 }
779785 }
786+ /* Only process slots actually filled by the second
787+ * pass; the directory may have shrunk since the
788+ * count pass. */
789+ fileFilled = i ;
780790
781- for (i = 0 ; i < fileCount ; i ++ ) {
791+ for (i = 0 ; i < fileFilled ; i ++ ) {
782792 /* Check if filename prefix matches */
783793 if (prefixLen > 0 ) {
784794 if ((int )WSTRLEN (fileNames [i ]) <= prefixLen ) {
0 commit comments