Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merges few missing extension related functions from ioq3. And fixes s…
…ecurity issue with /writeconfig on non-.cfg files.
  • Loading branch information
ensiform committed Apr 20, 2013
1 parent f5ba0fe commit 05928a5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
7 changes: 7 additions & 0 deletions codemp/qcommon/common.cpp
Expand Up @@ -1363,6 +1363,13 @@ void Com_WriteConfig_f( void ) {

Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );

if(!COM_CompareExtension(filename, ".cfg"))
{
Com_Printf( "Com_WriteConfig_f: Only the \".cfg\" extension is supported by this command!\n" );
return;
}

Com_Printf( "Writing %s.\n", filename );
Com_WriteConfigToFile( filename );
}
Expand Down
4 changes: 2 additions & 2 deletions codemp/qcommon/platform.h
Expand Up @@ -35,7 +35,7 @@ typedef struct _GUID {
#define stricmp Q_stricmp
#define RGB(r,g,b) ((COLORREF)((r) | ((g) << 8) | ((b) << 16)))

#define DLL_EXT "so"
#define DLL_EXT ".so"
#endif

#if defined (MACOS_X)
Expand Down Expand Up @@ -68,7 +68,7 @@ typedef struct _GUID {
#define RGB(r,g,b) ((COLORREF)((r) | ((g) << 8) | ((b) << 16)))

#define _isnan isnan
#define DLL_EXT "dylib"
#define DLL_EXT ".dylib"
#endif

#endif
73 changes: 34 additions & 39 deletions codemp/qcommon/q_shared.c
Expand Up @@ -93,21 +93,23 @@ char *COM_SkipPath (char *pathname)

/*
============
COM_StripExtension
COM_GetExtension
============
*/

#if 0 //jamp

void COM_StripExtension( const char *in, char *out ) {
while ( *in && *in != '.' ) {
*out++ = *in++;
}
*out = 0;
const char *COM_GetExtension( const char *name )
{
const char *dot = strrchr(name, '.'), *slash;
if (dot && (!(slash = strrchr(name, '/')) || slash < dot))
return dot + 1;
else
return "";
}

#else //iojamp

/*
============
COM_StripExtension
============
*/
void COM_StripExtension( const char *in, char *out, int destsize )
{
const char *dot = strrchr(in, '.'), *slash;
Expand All @@ -117,41 +119,36 @@ void COM_StripExtension( const char *in, char *out, int destsize )
Q_strncpyz(out, in, destsize);
}

#endif



/*
==================
COM_DefaultExtension
==================
*/
============
COM_CompareExtension
#if 0 //jamp
string compare the end of the strings and return qtrue if strings match
============
*/
qboolean COM_CompareExtension(const char *in, const char *ext)
{
int inlen, extlen;

void COM_DefaultExtension (char *path, int maxSize, const char *extension ) {
char oldPath[MAX_QPATH];
char *src;
inlen = strlen(in);
extlen = strlen(ext);

//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
src = path + strlen(path) - 1;
if(extlen <= inlen)
{
in += inlen - extlen;

while (*src != '/' && src != path) {
if ( *src == '.' ) {
return; // it has an extension
}
src--;
if(!Q_stricmp(in, ext))
return qtrue;
}

Q_strncpyz( oldPath, path, sizeof( oldPath ) );
Com_sprintf( path, maxSize, "%s%s", oldPath, extension );
return qfalse;
}

#else //iojamp

/*
==================
COM_DefaultExtension
==================
*/
void COM_DefaultExtension( char *path, int maxSize, const char *extension )
{
const char *dot = strrchr(path, '.'), *slash;
Expand All @@ -161,8 +158,6 @@ void COM_DefaultExtension( char *path, int maxSize, const char *extension )
Q_strcat(path, maxSize, extension);
}

#endif

/*
============================================================================
Expand Down
6 changes: 6 additions & 0 deletions codemp/qcommon/q_shared.h
Expand Up @@ -260,6 +260,8 @@ float FloatSwap( const float *f );
#define BigFloat(x) FloatSwap(&x)
#endif

#define DLL_EXT ".dylib"

#endif // MACOS_X


Expand Down Expand Up @@ -287,6 +289,8 @@ float FloatSwap( const float *f );
#define BigFloat
static inline float LittleFloat( const float l ) { return FloatSwap( &l ); }

#define DLL_EXT ".dylib"

#endif // __MACOS__


Expand Down Expand Up @@ -1560,7 +1564,9 @@ int Com_Clampi( int min, int max, int value ); //rwwRMG - added
float Com_Clamp( float min, float max, float value );

char *COM_SkipPath( char *pathname );
const char *COM_GetExtension( const char *name );
void COM_StripExtension( const char *in, char *out, int destsize );
qboolean COM_CompareExtension(const char *in, const char *ext);
void COM_DefaultExtension( char *path, int maxSize, const char *extension );

void COM_BeginParseSession( const char *name );
Expand Down
14 changes: 7 additions & 7 deletions codemp/unix/unix_main.cpp
Expand Up @@ -320,22 +320,22 @@ void *Sys_LoadDll( const char *name,
getcwd(curpath, sizeof(curpath));
#if defined __i386__
#ifndef NDEBUG
snprintf (fname, sizeof(fname), "%si386-debug.%s", name, DLL_EXT); // bk010205 - different DLL name
snprintf (fname, sizeof(fname), "%si386-debug%s", name, DLL_EXT); // bk010205 - different DLL name
#else
snprintf (fname, sizeof(fname), "%si386.%s", name, DLL_EXT);
snprintf (fname, sizeof(fname), "%si386%s", name, DLL_EXT);
#endif
#elif defined __x86_64__
#ifndef NDEBUG
snprintf (fname, sizeof(fname), "%sx86_64-debug.%s", name, DLL_EXT); // bk010205 - different DLL name
snprintf (fname, sizeof(fname), "%sx86_64-debug%s", name, DLL_EXT); // bk010205 - different DLL name
#else
snprintf (fname, sizeof(fname), "%sx86_64.%s", name, DLL_EXT);
snprintf (fname, sizeof(fname), "%sx86_64%s", name, DLL_EXT);
#endif
#elif defined __powerpc__ //rcg010207 - PPC support.
snprintf (fname, sizeof(fname), "%sppc.%s", name, DLL_EXT);
snprintf (fname, sizeof(fname), "%sppc%s", name, DLL_EXT);
#elif defined __axp__
snprintf (fname, sizeof(fname), "%saxp.%s", name, DLL_EXT);
snprintf (fname, sizeof(fname), "%saxp%s", name, DLL_EXT);
#elif defined __mips__
snprintf (fname, sizeof(fname), "%smips.%s", name, DLL_EXT);
snprintf (fname, sizeof(fname), "%smips%s", name, DLL_EXT);
#else
#error Unknown arch
#endif
Expand Down

0 comments on commit 05928a5

Please sign in to comment.