Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge some file writing extension checks from OpenJK.
  • Loading branch information
SmileTheory committed Mar 14, 2017
1 parent f61fe5f commit b173ac0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code/client/cl_console.c
Expand Up @@ -191,6 +191,12 @@ void Con_Dump_f (void)
Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".txt" );

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

f = FS_FOpenFileWrite( filename );
if (!f)
{
Expand Down
7 changes: 7 additions & 0 deletions code/qcommon/common.c
Expand Up @@ -2975,6 +2975,13 @@ void Com_WriteConfig_f( void ) {
return;
}


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

Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );
Com_Printf( "Writing %s.\n", filename );
Expand Down

2 comments on commit b173ac0

@Chomenor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check in Com_WriteConfig_f is messed up. You are currently just running COM_CompareExtension on an uninitialized buffer. That check needs to come after Q_strncpyz and COM_DefaultExtension.

@ensiform
Copy link

@ensiform ensiform commented on b173ac0 Mar 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed ^ It is correct in the original commit which it was based on.

Please sign in to comment.