[test-suite] r178660 - Removing sources of uncertainty from ClamAV
Renato Golin
renato.golin at linaro.org
Wed Apr 3 08:07:43 PDT 2013
Author: rengolin
Date: Wed Apr 3 10:07:42 2013
New Revision: 178660
URL: http://llvm.org/viewvc/llvm-project?rev=178660&view=rev
Log:
Removing sources of uncertainty from ClamAV
ClamAV is an anti-virus that scans directories by their
inode order, and thus being random in nature. This patch
does two things to address that: passes the files to scan
as a list (on the Makefile) and sorts the definition files
as they're read (readdb).
The result now should be identical on any machine/os/arch.
Modified:
test-suite/trunk/MultiSource/Applications/ClamAV/Makefile
test-suite/trunk/MultiSource/Applications/ClamAV/clamscan.reference_output
test-suite/trunk/MultiSource/Applications/ClamAV/libclamav_readdb.c
Modified: test-suite/trunk/MultiSource/Applications/ClamAV/Makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Applications/ClamAV/Makefile?rev=178660&r1=178659&r2=178660&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Applications/ClamAV/Makefile (original)
+++ test-suite/trunk/MultiSource/Applications/ClamAV/Makefile Wed Apr 3 10:07:42 2013
@@ -23,10 +23,27 @@ Source = $(addprefix libclamav_, \
# $(addprefix libclamav_lzma_, \
# LzmaStateDecode.c) \
+INPUT = $(PROJ_SRC_DIR)/inputs/clam.cab \
+ $(PROJ_SRC_DIR)/inputs/clamdoc.tar.gz \
+ $(PROJ_SRC_DIR)/inputs/clam.exe \
+ $(PROJ_SRC_DIR)/inputs/clam.exe.bz2 \
+ $(PROJ_SRC_DIR)/inputs/clam-v2.rar \
+ $(PROJ_SRC_DIR)/inputs/clam-v3.rar \
+ $(PROJ_SRC_DIR)/inputs/clam.zip \
+ $(PROJ_SRC_DIR)/inputs/README \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/Doc11.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/Doc1.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/Doc22.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/Doc2.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/doc3.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/docCLAMexe.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/rtf1.rtf \
+ $(PROJ_SRC_DIR)/inputs/rtf-test/rtf-novirus.rtf
+
PROG = clamscan
CPPFLAGS += -DHAVE_CONFIG_H -I. -DDONT_LOCK_DBDIRS
LDFLAGS = -lz
-RUN_OPTIONS = --debug --exclude-dir .svn --verbose -d$(PROJ_SRC_DIR)/dbdir -r $(PROJ_SRC_DIR)/inputs/*
+RUN_OPTIONS = --debug --exclude-dir .svn --verbose -d$(PROJ_SRC_DIR)/dbdir -r $(INPUT)
include $(LEVEL)/Makefile.config
Modified: test-suite/trunk/MultiSource/Applications/ClamAV/clamscan.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Applications/ClamAV/clamscan.reference_output?rev=178660&r1=178659&r2=178660&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Applications/ClamAV/clamscan.reference_output (original)
+++ test-suite/trunk/MultiSource/Applications/ClamAV/clamscan.reference_output Wed Apr 3 10:07:42 2013
@@ -246,18 +246,6 @@ Module PHISHING %s
* Submodule %10s: %s
-Scanning README
-README: OK
-Scanning clam-v2.rar
-LibClamAV Warning: RAR code not compiled-in
-Recognized %s file
-
-clam-v2.rar: OK
-Scanning clam-v3.rar
-LibClamAV Warning: RAR code not compiled-in
-Recognized %s file
-
-clam-v3.rar: OK
Scanning clam.cab
Recognized %s file
@@ -361,160 +349,6 @@ Section's memory is writeable
EntryPoint offset: 0x%x (%d)
clam.cab: OK
-Scanning clam.exe
-Recognized %s file
-
-Matched signature for file type %s
-
-e_lfanew == %d
-
-Machine type: 80386
-
-NumberOfSections: %d
-
-TimeDateStamp: %s
-SizeOfOptionalHeader: %x
-
-File format: PE
-
-MajorLinkerVersion: %d
-
-MinorLinkerVersion: %d
-
-SizeOfCode: 0x%x
-
-SizeOfInitializedData: 0x%x
-
-SizeOfUninitializedData: 0x%x
-
-AddressOfEntryPoint: 0x%x
-
-BaseOfCode: 0x%x
-
-SectionAlignment: 0x%x
-
-FileAlignment: 0x%x
-
-MajorSubsystemVersion: %d
-
-MinorSubsystemVersion: %d
-
-SizeOfImage: 0x%x
-
-SizeOfHeaders: 0x%x
-
-NumberOfRvaAndSizes: %d
-
-Subsystem: Win32 GUI
-
-------------------------------------
-
-Section %d
-
-Section name: %s
-
-Section data (from headers - in memory)
-
-VirtualSize: 0x%x 0x%x
-
-VirtualAddress: 0x%x 0x%x
-
-SizeOfRawData: 0x%x 0x%x
-
-PointerToRawData: 0x%x 0x%x
-
-Section's memory is writeable
-
-------------------------------------
-
-EntryPoint offset: 0x%x (%d)
-
-clam.exe: OK
-Scanning clam.exe.bz2
-Recognized %s file
-
-clam.exe.bz2: OK
-Scanning clam.zip
-Recognized %s file
-
-in scanzip()
-
-Unzip: __zip_find_disk_trailer: found file header at %u, shift %u
-
-Zip: %s, crc32: 0x%x, offset: %u, encrypted: %u, compressed: %u, normal: %u, method: %u, ratio: %u (max: %u)
-
-Zip: File decompressed to %s
-
-Recognized %s file
-
-Matched signature for file type %s
-
-e_lfanew == %d
-
-Machine type: 80386
-
-NumberOfSections: %d
-
-TimeDateStamp: %s
-SizeOfOptionalHeader: %x
-
-File format: PE
-
-MajorLinkerVersion: %d
-
-MinorLinkerVersion: %d
-
-SizeOfCode: 0x%x
-
-SizeOfInitializedData: 0x%x
-
-SizeOfUninitializedData: 0x%x
-
-AddressOfEntryPoint: 0x%x
-
-BaseOfCode: 0x%x
-
-SectionAlignment: 0x%x
-
-FileAlignment: 0x%x
-
-MajorSubsystemVersion: %d
-
-MinorSubsystemVersion: %d
-
-SizeOfImage: 0x%x
-
-SizeOfHeaders: 0x%x
-
-NumberOfRvaAndSizes: %d
-
-Subsystem: Win32 GUI
-
-------------------------------------
-
-Section %d
-
-Section name: %s
-
-Section data (from headers - in memory)
-
-VirtualSize: 0x%x 0x%x
-
-VirtualAddress: 0x%x 0x%x
-
-SizeOfRawData: 0x%x 0x%x
-
-PointerToRawData: 0x%x 0x%x
-
-Section's memory is writeable
-
-------------------------------------
-
-EntryPoint offset: 0x%x (%d)
-
-Matched signature for file type %s at %u
-
-clam.zip: OK
Scanning clamdoc.tar.gz
Recognized %s file
@@ -1105,31 +939,7 @@ Recognized %s file
in cli_check_jpeg_exploit()
clamdoc.tar.gz: OK
-Scanning Doc1.rtf
-Recognized %s file
-
-in cli_scanrtf()
-
-RTF: waiting for magic
-
-RTF: description length:%lu
-
-RTF: in WAIT_DESC
-
-Preparing to dump rtf embedded object, description:%s
-
-RTF: next state: wait_data_size
-
-RTF: in WAIT_DATA_SIZE
-
-Dumping rtf embedded object of size:%lu
-
-RTF: next state: DUMP_DATA
-
-RTF:Scanning embedded object:%s
-
-Decoding ole object
-
+Scanning clam.exe
Recognized %s file
Matched signature for file type %s
@@ -1197,59 +1007,132 @@ Section's memory is writeable
EntryPoint offset: 0x%x (%d)
-RTF: waiting for magic
+clam.exe: OK
+Scanning clam.exe.bz2
+Recognized %s file
-Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
+clam.exe.bz2: OK
+Scanning clam-v2.rar
+LibClamAV Warning: RAR code not compiled-in
+Recognized %s file
-RTF: description length:%lu
+clam-v2.rar: OK
+Scanning clam-v3.rar
+LibClamAV Warning: RAR code not compiled-in
+Recognized %s file
-RTF: in WAIT_DESC
+clam-v3.rar: OK
+Scanning clam.zip
+Recognized %s file
-Preparing to dump rtf embedded object, description:%s
+in scanzip()
-RTF: next state: wait_data_size
+Unzip: __zip_find_disk_trailer: found file header at %u, shift %u
-RTF: in WAIT_DATA_SIZE
+Zip: %s, crc32: 0x%x, offset: %u, encrypted: %u, compressed: %u, normal: %u, method: %u, ratio: %u (max: %u)
-Dumping rtf embedded object of size:%lu
+Zip: File decompressed to %s
-RTF: next state: DUMP_DATA
+Recognized %s file
-RTF:Scanning embedded object:%s
+Matched signature for file type %s
-Decoding ole object
+e_lfanew == %d
-Small data (%u bytes)
+Machine type: 80386
-Doc1.rtf: OK
-Scanning Doc11.rtf
-Recognized %s file
+NumberOfSections: %d
-in cli_scanrtf()
+TimeDateStamp: %s
+SizeOfOptionalHeader: %x
-RTF: waiting for magic
+File format: PE
-RTF: description length:%lu
+MajorLinkerVersion: %d
-RTF: in WAIT_DESC
+MinorLinkerVersion: %d
-Preparing to dump rtf embedded object, description:%s
+SizeOfCode: 0x%x
-RTF: next state: wait_data_size
+SizeOfInitializedData: 0x%x
-RTF: in WAIT_DATA_SIZE
+SizeOfUninitializedData: 0x%x
-Dumping rtf embedded object of size:%lu
+AddressOfEntryPoint: 0x%x
-RTF: next state: DUMP_DATA
+BaseOfCode: 0x%x
-RTF:Scanning embedded object:%s
+SectionAlignment: 0x%x
-Recognized %s file
+FileAlignment: 0x%x
-in cli_scanole2()
+MajorSubsystemVersion: %d
-in cli_ole2_extract()
+MinorSubsystemVersion: %d
+
+SizeOfImage: 0x%x
+
+SizeOfHeaders: 0x%x
+
+NumberOfRvaAndSizes: %d
+
+Subsystem: Win32 GUI
+
+------------------------------------
+
+Section %d
+
+Section name: %s
+
+Section data (from headers - in memory)
+
+VirtualSize: 0x%x 0x%x
+
+VirtualAddress: 0x%x 0x%x
+
+SizeOfRawData: 0x%x 0x%x
+
+PointerToRawData: 0x%x 0x%x
+
+Section's memory is writeable
+
+------------------------------------
+
+EntryPoint offset: 0x%x (%d)
+
+Matched signature for file type %s at %u
+
+clam.zip: OK
+Scanning README
+README: OK
+Scanning Doc11.rtf
+Recognized %s file
+
+in cli_scanrtf()
+
+RTF: waiting for magic
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Recognized %s file
+
+in cli_scanole2()
+
+in cli_ole2_extract()
mmap'ed file
@@ -1494,7 +1377,124 @@ RTF: waiting for magic
Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
Doc11.rtf: OK
-Scanning Doc2.rtf
+Scanning Doc1.rtf
+Recognized %s file
+
+in cli_scanrtf()
+
+RTF: waiting for magic
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Decoding ole object
+
+Recognized %s file
+
+Matched signature for file type %s
+
+e_lfanew == %d
+
+Machine type: 80386
+
+NumberOfSections: %d
+
+TimeDateStamp: %s
+SizeOfOptionalHeader: %x
+
+File format: PE
+
+MajorLinkerVersion: %d
+
+MinorLinkerVersion: %d
+
+SizeOfCode: 0x%x
+
+SizeOfInitializedData: 0x%x
+
+SizeOfUninitializedData: 0x%x
+
+AddressOfEntryPoint: 0x%x
+
+BaseOfCode: 0x%x
+
+SectionAlignment: 0x%x
+
+FileAlignment: 0x%x
+
+MajorSubsystemVersion: %d
+
+MinorSubsystemVersion: %d
+
+SizeOfImage: 0x%x
+
+SizeOfHeaders: 0x%x
+
+NumberOfRvaAndSizes: %d
+
+Subsystem: Win32 GUI
+
+------------------------------------
+
+Section %d
+
+Section name: %s
+
+Section data (from headers - in memory)
+
+VirtualSize: 0x%x 0x%x
+
+VirtualAddress: 0x%x 0x%x
+
+SizeOfRawData: 0x%x 0x%x
+
+PointerToRawData: 0x%x 0x%x
+
+Section's memory is writeable
+
+------------------------------------
+
+EntryPoint offset: 0x%x (%d)
+
+RTF: waiting for magic
+
+Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Decoding ole object
+
+Small data (%u bytes)
+
+Doc1.rtf: OK
+Scanning Doc22.rtf
Recognized %s file
in cli_scanrtf()
@@ -1765,8 +1765,8 @@ RTF: waiting for magic
Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
-Doc2.rtf: OK
-Scanning Doc22.rtf
+Doc22.rtf: OK
+Scanning Doc2.rtf
Recognized %s file
in cli_scanrtf()
@@ -2037,7 +2037,7 @@ RTF: waiting for magic
Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
-Doc22.rtf: OK
+Doc2.rtf: OK
Scanning doc3.rtf
Recognized %s file
@@ -2511,6 +2511,167 @@ Decoding ole object
Small data (%u bytes)
docCLAMexe.rtf: OK
+Scanning rtf1.rtf
+Recognized %s file
+
+in cli_scanrtf()
+
+RTF: waiting for magic
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Decoding ole object
+
+RTF: waiting for magic
+
+Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Decoding ole object
+
+Small data (%u bytes)
+
+RTF: waiting for magic
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Decoding ole object
+
+Recognized %s file
+
+Matched signature for file type %s
+
+e_lfanew == %d
+
+Machine type: 80386
+
+NumberOfSections: %d
+
+TimeDateStamp: %s
+SizeOfOptionalHeader: %x
+
+File format: PE
+
+MajorLinkerVersion: %d
+
+MinorLinkerVersion: %d
+
+SizeOfCode: 0x%x
+
+SizeOfInitializedData: 0x%x
+
+SizeOfUninitializedData: 0x%x
+
+AddressOfEntryPoint: 0x%x
+
+BaseOfCode: 0x%x
+
+SectionAlignment: 0x%x
+
+FileAlignment: 0x%x
+
+MajorSubsystemVersion: %d
+
+MinorSubsystemVersion: %d
+
+SizeOfImage: 0x%x
+
+SizeOfHeaders: 0x%x
+
+NumberOfRvaAndSizes: %d
+
+Subsystem: Win32 GUI
+
+------------------------------------
+
+Section %d
+
+Section name: %s
+
+Section data (from headers - in memory)
+
+VirtualSize: 0x%x 0x%x
+
+VirtualAddress: 0x%x 0x%x
+
+SizeOfRawData: 0x%x 0x%x
+
+PointerToRawData: 0x%x 0x%x
+
+Section's memory is writeable
+
+------------------------------------
+
+EntryPoint offset: 0x%x (%d)
+
+RTF: waiting for magic
+
+Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
+
+RTF: description length:%lu
+
+RTF: in WAIT_DESC
+
+Preparing to dump rtf embedded object, description:%s
+
+RTF: next state: wait_data_size
+
+RTF: in WAIT_DATA_SIZE
+
+Dumping rtf embedded object of size:%lu
+
+RTF: next state: DUMP_DATA
+
+RTF:Scanning embedded object:%s
+
+Decoding ole object
+
+Small data (%u bytes)
+
+rtf1.rtf: OK
Scanning rtf-novirus.rtf
Recognized %s file
@@ -2783,167 +2944,6 @@ RTF: waiting for magic
Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
rtf-novirus.rtf: OK
-Scanning rtf1.rtf
-Recognized %s file
-
-in cli_scanrtf()
-
-RTF: waiting for magic
-
-RTF: description length:%lu
-
-RTF: in WAIT_DESC
-
-Preparing to dump rtf embedded object, description:%s
-
-RTF: next state: wait_data_size
-
-RTF: in WAIT_DATA_SIZE
-
-Dumping rtf embedded object of size:%lu
-
-RTF: next state: DUMP_DATA
-
-RTF:Scanning embedded object:%s
-
-Decoding ole object
-
-RTF: waiting for magic
-
-Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
-
-RTF: description length:%lu
-
-RTF: in WAIT_DESC
-
-Preparing to dump rtf embedded object, description:%s
-
-RTF: next state: wait_data_size
-
-RTF: in WAIT_DATA_SIZE
-
-Dumping rtf embedded object of size:%lu
-
-RTF: next state: DUMP_DATA
-
-RTF:Scanning embedded object:%s
-
-Decoding ole object
-
-Small data (%u bytes)
-
-RTF: waiting for magic
-
-RTF: description length:%lu
-
-RTF: in WAIT_DESC
-
-Preparing to dump rtf embedded object, description:%s
-
-RTF: next state: wait_data_size
-
-RTF: in WAIT_DATA_SIZE
-
-Dumping rtf embedded object of size:%lu
-
-RTF: next state: DUMP_DATA
-
-RTF:Scanning embedded object:%s
-
-Decoding ole object
-
-Recognized %s file
-
-Matched signature for file type %s
-
-e_lfanew == %d
-
-Machine type: 80386
-
-NumberOfSections: %d
-
-TimeDateStamp: %s
-SizeOfOptionalHeader: %x
-
-File format: PE
-
-MajorLinkerVersion: %d
-
-MinorLinkerVersion: %d
-
-SizeOfCode: 0x%x
-
-SizeOfInitializedData: 0x%x
-
-SizeOfUninitializedData: 0x%x
-
-AddressOfEntryPoint: 0x%x
-
-BaseOfCode: 0x%x
-
-SectionAlignment: 0x%x
-
-FileAlignment: 0x%x
-
-MajorSubsystemVersion: %d
-
-MinorSubsystemVersion: %d
-
-SizeOfImage: 0x%x
-
-SizeOfHeaders: 0x%x
-
-NumberOfRvaAndSizes: %d
-
-Subsystem: Win32 GUI
-
-------------------------------------
-
-Section %d
-
-Section name: %s
-
-Section data (from headers - in memory)
-
-VirtualSize: 0x%x 0x%x
-
-VirtualAddress: 0x%x 0x%x
-
-SizeOfRawData: 0x%x 0x%x
-
-PointerToRawData: 0x%x 0x%x
-
-Section's memory is writeable
-
-------------------------------------
-
-EntryPoint offset: 0x%x (%d)
-
-RTF: waiting for magic
-
-Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu
-
-RTF: description length:%lu
-
-RTF: in WAIT_DESC
-
-Preparing to dump rtf embedded object, description:%s
-
-RTF: next state: wait_data_size
-
-RTF: in WAIT_DATA_SIZE
-
-Dumping rtf embedded object of size:%lu
-
-RTF: next state: DUMP_DATA
-
-RTF:Scanning embedded object:%s
-
-Decoding ole object
-
-Small data (%u bytes)
-
-rtf1.rtf: OK
Cleaning up phishcheck
Freeing phishcheck struct
@@ -2954,7 +2954,7 @@ Phishcheck cleaned up
----------- SCAN SUMMARY -----------
Known viruses: 19590
Engine version: devel-20071218
-Scanned directories: 1
+Scanned directories: 0
Scanned files: 16
Infected files: 0
Data scanned: 1.89 MB
Modified: test-suite/trunk/MultiSource/Applications/ClamAV/libclamav_readdb.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Applications/ClamAV/libclamav_readdb.c?rev=178660&r1=178659&r2=178660&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Applications/ClamAV/libclamav_readdb.c (original)
+++ test-suite/trunk/MultiSource/Applications/ClamAV/libclamav_readdb.c Wed Apr 3 10:07:42 2013
@@ -1065,10 +1065,25 @@ int cl_loaddb(const char *filename, stru
cli_strbcasestr(ext, ".cvd") \
)
+static int dirent_compare(const struct dirent *a, const struct dirent *b) {
+ int ret = strcmp(a->d_name, b->d_name);
+ if (ret != 0)
+ return ret;
+ if (a->d_type < b->d_type) return -1;
+ if (a->d_type > b->d_type) return 1;
+ if (a->d_reclen < b->d_reclen) return -1;
+ if (a->d_reclen > b->d_reclen) return 1;
+ return 0;
+}
+
static int cli_loaddbdir_l(const char *dirname, struct cl_engine **engine, unsigned int *signo, unsigned int options)
{
DIR *dd;
struct dirent *dent;
+ /* To sort the files in the temp dir to get repeatable results */
+ const unsigned MAX_DIRENTS = 20;
+ struct dirent dents[MAX_DIRENTS];
+ unsigned ndents;
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
union {
struct dirent d;
@@ -1100,6 +1115,8 @@ static int cli_loaddbdir_l(const char *d
return CL_EOPEN;
}
+ ndents=0;
+ memset(&dents, 0, sizeof(dents));
#ifdef HAVE_READDIR_R_3
while(!readdir_r(dd, &result.d, &dent) && dent) {
#elif defined(HAVE_READDIR_R_2)
@@ -1107,10 +1124,21 @@ static int cli_loaddbdir_l(const char *d
#else
while((dent = readdir(dd))) {
#endif
+ memcpy(&dents[ndents], dent, sizeof(struct dirent));
+ ndents++;
+ if (ndents == MAX_DIRENTS) {
+ cli_errmsg("cli_loaddbdir(): Too many files, increase MAX_DIRENTS\n");
+ return CL_EOPEN;
+ }
+ }
+
+ qsort(dents, ndents, sizeof(struct dirent), dirent_compare);
+
+ for (unsigned i=0; i<ndents; i++) {
+ dent = &dents[i];
#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN))
- if(dent->d_ino)
+ if(dent->d_ino) {
#endif
- {
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && CLI_DBEXT(dent->d_name)) {
dbfile = (char *) cli_malloc(strlen(dent->d_name) + strlen(dirname) + 2);
@@ -1135,7 +1163,9 @@ static int cli_loaddbdir_l(const char *d
}
free(dbfile);
}
+#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(C_CYGWIN))
}
+#endif
}
closedir(dd);
More information about the llvm-commits
mailing list