Skip to content

Commit

Permalink
report 0x0xADDR as invalid (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Dec 21, 2024
1 parent 92509d9 commit 93eca32
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rcheevos/memref.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ int rc_parse_memref(const char** memaddr, uint8_t* size, uint32_t* address) {
/* case 'y': case 'Y': 64 bit? */
/* case 'z': case 'Z': 128 bit? */

case '0': case '1': case '2': case '3': case '4':
case '0':
if (*aux == 'x') /* user mistyped an extra 0x: 0x0xabcd */
return RC_INVALID_MEMORY_OPERAND;
/* fallthrough */

case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
Expand Down
9 changes: 9 additions & 0 deletions src/rcheevos/richpresence.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,20 @@ void rc_parse_richpresence_internal(rc_richpresence_t* self, const char* script,
*nextdisplay = rc_parse_richpresence_display_internal(ptr + 1, endline, parse, firstlookup);
if (parse->offset < 0)
return;

trigger = &((*nextdisplay)->trigger);
rc_parse_trigger_internal(trigger, &line, parse);
if (parse->offset < 0)
return;

if (line != ptr) {
/* incomplete read */
parse->offset = RC_INVALID_OPERATOR;
return;
}

(*nextdisplay)->has_required_hits = parse->has_required_hits;

if (parse->buffer)
nextdisplay = &((*nextdisplay)->next);
}
Expand Down
3 changes: 3 additions & 0 deletions test/rcheevos/test_operand.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ static void test_parse_memory_references() {
TEST_PARAMS4(test_parse_operand, "0xHABCD", RC_OPERAND_ADDRESS, RC_MEMSIZE_8_BITS, 0xABCDU);
TEST_PARAMS4(test_parse_operand, "0xhabcd", RC_OPERAND_ADDRESS, RC_MEMSIZE_8_BITS, 0xABCDU);
TEST_PARAMS4(test_parse_operand, "fFABCD", RC_OPERAND_ADDRESS, RC_MEMSIZE_FLOAT, 0xABCDU);

/* doubled up prefix */
TEST_PARAMS3(test_parse_error_operand, "0x0xH1234", 0, RC_INVALID_MEMORY_OPERAND);
}

static void test_parse_delta_memory_references() {
Expand Down
15 changes: 15 additions & 0 deletions test/rcheevos/test_richpresence.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ static void test_conditional_display_unnecessary_measured_indirect() {
assert_richpresence_output(richpresence, &memory, "True");
}

static void test_conditional_display_invalid() {
int lines_read = 0;
ASSERT_NUM_EQUALS(rc_richpresence_size_lines("Display:\n?I:0x0x0000=1?True\nFalse\n", &lines_read), RC_INVALID_MEMORY_OPERAND);
ASSERT_NUM_EQUALS(lines_read, 2);

ASSERT_NUM_EQUALS(rc_richpresence_size_lines("Display:\n?0x0000=1 0x0001=2?True\nFalse\n", &lines_read), RC_INVALID_OPERATOR);
ASSERT_NUM_EQUALS(lines_read, 2);
}

static void test_macro_value_adjusted_negative() {
uint8_t ram[] = { 0x00, 0x12, 0x34, 0xAB, 0x56 };
memory_t memory;
Expand Down Expand Up @@ -527,6 +536,10 @@ static void test_macro_value_remember_recall() {
assert_richpresence_output(richpresence, &memory, "Result is 3");
}

static void test_macro_value_invalid() {
ASSERT_NUM_EQUALS(rc_richpresence_size("Format:Points\nFormatType=VALUE\n\nDisplay:\n@Points(0x0x0001) Points"), RC_INVALID_MEMORY_OPERAND);
}

static void test_macro_hundreds() {
uint8_t ram[] = { 0x00, 0x12, 0x34, 0xAB, 0x56 };
memory_t memory;
Expand Down Expand Up @@ -1343,6 +1356,7 @@ void test_richpresence(void) {
TEST(test_conditional_display_indirect);
TEST(test_conditional_display_unnecessary_measured);
TEST(test_conditional_display_unnecessary_measured_indirect);
TEST(test_conditional_display_invalid);

/* value macros */
TEST(test_macro_value);
Expand All @@ -1356,6 +1370,7 @@ void test_richpresence(void) {
TEST(test_macro_value_divide_by_zero);
TEST(test_macro_value_divide_by_self);
TEST(test_macro_value_remember_recall);
TEST(test_macro_value_invalid);

/* hundreds macro */
TEST(test_macro_hundreds);
Expand Down

0 comments on commit 93eca32

Please sign in to comment.