From 7a50a52582d160882818d853ba2bd9104bf59b73 Mon Sep 17 00:00:00 2001 From: Richard Jenkins Date: Fri, 21 Apr 2017 16:51:07 +0100 Subject: [PATCH] Harden console command error checking, reduce command array sizes --- src/openrct2/interface/console.c | 8 ++++---- src/openrct2/ride/ride.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openrct2/interface/console.c b/src/openrct2/interface/console.c index 1e70446007..d41d61d0cf 100644 --- a/src/openrct2/interface/console.c +++ b/src/openrct2/interface/console.c @@ -484,7 +484,7 @@ static sint32 cc_rides(const utf8 **argv, sint32 argc) } } else if (strcmp(argv[1], "mode") == 0) { - bool int_valid[3] = { 0 }; + bool int_valid[2] = { 0 }; sint32 ride_index = console_parse_int(argv[2], &int_valid[0]); sint32 mode = console_parse_int(argv[3], &int_valid[1]); if (!int_valid[0] || !int_valid[1]) { @@ -493,10 +493,10 @@ static sint32 cc_rides(const utf8 **argv, sint32 argc) console_printf("Ride index must not be negative"); } else { rct_ride *ride = get_ride(ride_index); - if (mode <= 0) { - console_printf("Ride mode must be strictly positive"); + if (mode <= 0 || mode > RIDE_MODE_COUNT) { + console_printf("Invalid ride mode."); } - else if (ride->type == RIDE_TYPE_NULL) { + else if (ride == NULL || ride->type == RIDE_TYPE_NULL) { console_printf("No ride found with index %d", ride_index); } else { diff --git a/src/openrct2/ride/ride.h b/src/openrct2/ride/ride.h index d73c13abdc..e3967c13a3 100644 --- a/src/openrct2/ride/ride.h +++ b/src/openrct2/ride/ride.h @@ -902,6 +902,8 @@ extern const rct_ride_properties RideProperties[RIDE_TYPE_COUNT]; #define MAX_RIDES 255 +#define RIDE_MODE_COUNT 36 + #define MAX_RIDE_MEASUREMENTS 8 #define RIDE_VALUE_UNDEFINED 0xFFFF #define RIDE_INITIAL_RELIABILITY ((100 << 8) - 1)