diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-04-19 14:21:57 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-04-26 15:43:09 +0200 |
commit | b7a35bd780dfc454ac485afd0d75258f18549e5f (patch) | |
tree | bf5a82b0bd4e65024525aa9e34171bf48a71b9fa | |
parent | f933ac79a6061abee7cd367bb3b72e71928eaaac (diff) |
Fix undefined behavior in !rshow.
-rw-r--r-- | src/game/g_admin.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/game/g_admin.c b/src/game/g_admin.c index 9b8945a..296d403 100644 --- a/src/game/g_admin.c +++ b/src/game/g_admin.c @@ -10152,37 +10152,37 @@ qboolean G_admin_rshow( gentity_t *ent, int skiparg ) char arg2[ 5 ]; char duration[ 32 ]; int ID, secs, t; - g_admin_report_t *report; - g_admin_archive_t *archive; qtime_t qt; - t = trap_RealTime( &qt ); - if( G_SayArgc() < 2 + skiparg ) { ADMP( "^3!rshow: ^7usage: !rshow [report#] (!) - adding ! shows archive# instead of report#\n" ); return qfalse; } + t = trap_RealTime( &qt ); + G_SayArgv( 1 + skiparg, arg2, sizeof( arg2 ) ); ID = atoi( arg2 ); G_SayArgv( 2 + skiparg, tmp, sizeof( tmp ) ); - archive = g_admin_archives[ ID - 1 ]; - report = g_admin_reports[ ID - 1 ]; - if( !strcmp( tmp, "!" ) ) { - if( ID < 1 || - ID > MAX_ADMIN_ARCHIVES || - !archive ) + g_admin_archive_t *archive; + + if( ID < 1 || ID > MAX_ADMIN_ARCHIVES ) { + invalid_archive: ADMP( "^3!rshow: ^7invalid archive#\n" ); return qfalse; } - secs = ( archive->expires - t ); - G_admin_duration( secs, duration, sizeof( duration ) ); + archive = g_admin_archives[ ID - 1 ]; + if( !archive ) + goto invalid_archive; + + secs = ( archive->expires - t ); + G_admin_duration( secs, duration, sizeof( duration ) ); ADMP( va( "%4i %s^7 %-15s Expires: %s\n" " | Reported by: %-15s^7 Level:%2i\n" @@ -10202,17 +10202,21 @@ qboolean G_admin_rshow( gentity_t *ent, int skiparg ) archive->players, archive->admins, archive->note ) ); - - return qtrue; - } - else if( ID < 1 || - ID > MAX_ADMIN_REPORTS || - !report ) + else { - ADMP( "^3!rshow: ^7invalid report#\n" ); - return qfalse; - } + g_admin_report_t *report; + + if( ID < 1 || ID > MAX_ADMIN_REPORTS ) + { + invalid_report: + ADMP( "^3!rshow: ^7invalid report#\n" ); + return qfalse; + } + + report = g_admin_reports[ ID - 1 ]; + if( !report ) + goto invalid_report; secs = ( report->expires - t ); G_admin_duration( secs, duration, sizeof( duration ) ); @@ -10235,8 +10239,9 @@ qboolean G_admin_rshow( gentity_t *ent, int skiparg ) report->players, report->admins, report->note ) ); + } - return qtrue; + return qtrue; } qboolean G_admin_scrim(gentity_t *ent, int skiparg ) |