summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2007-08-22 17:23:57 +0000
committerAndrey Nazarov <skuller@skuller.net>2007-08-22 17:23:57 +0000
commit1bef88894b7d80308460f480fb84958f65922e02 (patch)
treec7d6cd2b9a0bad7405ca75b79eda9df2d6471bac
parente6f9f100490b454a271f69f4af58eafbde92a87d (diff)
FS_ExtCmp now correctly handles complex extensions, e.g. '.dm2.gz'.
Fixed NULL pointer dereference when CL_Disconnect is called before client finishes initialization.
-rw-r--r--source/cl_main.c2
-rw-r--r--source/files.c48
-rw-r--r--source/sys_unix.c7
3 files changed, 33 insertions, 24 deletions
diff --git a/source/cl_main.c b/source/cl_main.c
index bc04446..2441e8c 100644
--- a/source/cl_main.c
+++ b/source/cl_main.c
@@ -641,7 +641,7 @@ This is also called on Com_Error, so it shouldn't cause any errors
=====================
*/
void CL_Disconnect( comErrorType_t type, const char *text ) {
- if ( cls.state != ca_disconnected ) {
+ if ( cls.state > ca_disconnected ) {
EXEC_TRIGGER( cl_disconnectcmd );
}
diff --git a/source/files.c b/source/files.c
index 1f1adea..b2c9a4e 100644
--- a/source/files.c
+++ b/source/files.c
@@ -1756,35 +1756,47 @@ qboolean FS_WildCmp( const char *filter, const char *string ) {
return qfalse;
}
-qboolean FS_ExtCmp( const char *ext, const char *string ) {
+qboolean FS_ExtCmp( const char *ext, const char *name ) {
int c1, c2;
- const char *s;
-
+ const char *e, *n, *l;
+
+ if( !name[0] || !ext[0] ) {
+ return qfalse;
+ }
+
+ for( l = name; l[1]; l++ )
+ ;
+
+ for( e = ext; e[1]; e++ )
+ ;
+
rescan:
- s = string;
+ n = l;
do {
- c1 = *ext++;
- c2 = *s++;
+ c1 = *e--;
+ c2 = *n--;
if( c1 == ';' ) {
- if( c2 ) {
- goto rescan;
- }
- return qtrue;
+ break; // matched
}
- c1 = Q_tolower( c1 );
- c2 = Q_tolower( c2 );
if( c1 != c2 ) {
- while( c1 ) {
- c1 = *ext++;
- if( c1 == ';' ) {
- goto rescan;
+ c1 = Q_tolower( c1 );
+ c2 = Q_tolower( c2 );
+ if( c1 != c2 ) {
+ while( e > ext ) {
+ c1 = *e--;
+ if( c1 == ';' ) {
+ goto rescan;
+ }
}
+ return qfalse;
}
+ }
+ if( n < name ) {
return qfalse;
}
- } while( c1 );
+ } while( e >= ext );
return qtrue;
}
@@ -1903,7 +1915,7 @@ char **FS_ListFiles( const char *path, const char *extension,
}
// check extension
- if( extension && !FS_ExtCmp( extension, COM_FileExtension( name ) ) ) {
+ if( extension && !FS_ExtCmp( extension, name ) ) {
continue;
}
diff --git a/source/sys_unix.c b/source/sys_unix.c
index 8596ef7..b7e88d0 100644
--- a/source/sys_unix.c
+++ b/source/sys_unix.c
@@ -1012,11 +1012,8 @@ char **Sys_ListFiles( const char *path, const char *extension,
}
}
- if( extension ) {
- s = COM_FileExtension( findInfo->d_name );
- if( !FS_ExtCmp( extension, s ) ) {
- continue;
- }
+ if( extension && !FS_ExtCmp( extension, findInfo->d_name ) ) {
+ continue;
}
if( flags & FS_SEARCH_SAVEPATH ) {