mirror of
https://github.com/libretro/RetroArch
synced 2025-03-31 10:20:41 +00:00
Merge pull request #10212 from Jamiras/cheevos_rp_buffer_overflow
(cheevos) prevent buffer overflow when encountering an unknown macro
This commit is contained in:
commit
a18b29743e
@ -666,7 +666,7 @@ static int rcheevos_parse(const char* json)
|
|||||||
lboard->format = rc_parse_format(lboard->info->format);
|
lboard->format = rc_parse_format(lboard->info->format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rcheevos_locals.patchdata.richpresence_script)
|
if (rcheevos_locals.patchdata.richpresence_script && *rcheevos_locals.patchdata.richpresence_script)
|
||||||
{
|
{
|
||||||
int buffer_size = rc_richpresence_size(rcheevos_locals.patchdata.richpresence_script);
|
int buffer_size = rc_richpresence_size(rcheevos_locals.patchdata.richpresence_script);
|
||||||
if (buffer_size <= 0)
|
if (buffer_size <= 0)
|
||||||
@ -681,8 +681,8 @@ static int rcheevos_parse(const char* json)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *buffer = (char*)malloc(buffer_size);
|
char *rp_buffer = (char*)malloc(buffer_size);
|
||||||
rcheevos_locals.richpresence.richpresence = rc_parse_richpresence(buffer, rcheevos_locals.patchdata.richpresence_script, NULL, 0);
|
rcheevos_locals.richpresence.richpresence = rc_parse_richpresence(rp_buffer, rcheevos_locals.patchdata.richpresence_script, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rcheevos_locals.richpresence.evaluation[0] = '\0';
|
rcheevos_locals.richpresence.evaluation[0] = '\0';
|
||||||
|
18
deps/rcheevos/src/rcheevos/richpresence.c
vendored
18
deps/rcheevos/src/rcheevos/richpresence.c
vendored
@ -8,7 +8,8 @@
|
|||||||
/* special formats only used by rc_richpresence_display_part_t.display_type. must not overlap other RC_FORMAT values */
|
/* special formats only used by rc_richpresence_display_part_t.display_type. must not overlap other RC_FORMAT values */
|
||||||
enum {
|
enum {
|
||||||
RC_FORMAT_STRING = 101,
|
RC_FORMAT_STRING = 101,
|
||||||
RC_FORMAT_LOOKUP = 102
|
RC_FORMAT_LOOKUP = 102,
|
||||||
|
RC_FORMAT_UNKNOWN_MACRO = 103
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* rc_parse_line(const char* line, const char** end) {
|
static const char* rc_parse_line(const char* line, const char** end) {
|
||||||
@ -161,10 +162,15 @@ static rc_richpresence_display_t* rc_parse_richpresence_display_internal(const c
|
|||||||
*next = part;
|
*next = part;
|
||||||
next = &part->next;
|
next = &part->next;
|
||||||
|
|
||||||
ptr = line;
|
/* find the closing parenthesis */
|
||||||
|
while (ptr < endline && *ptr != ')')
|
||||||
|
++ptr;
|
||||||
|
if (*ptr == ')')
|
||||||
|
++ptr;
|
||||||
|
|
||||||
part->display_type = RC_FORMAT_STRING;
|
/* assert: the allocated string is going to be smaller than the memory used for the parameter of the macro */
|
||||||
part->text = rc_alloc_str(parse, "[Unknown macro]", 15);
|
part->display_type = RC_FORMAT_UNKNOWN_MACRO;
|
||||||
|
part->text = rc_alloc_str(parse, line, ptr - line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,6 +428,10 @@ int rc_evaluate_richpresence(rc_richpresence_t* richpresence, char* buffer, unsi
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RC_FORMAT_UNKNOWN_MACRO:
|
||||||
|
chars = snprintf(ptr, buffersize, "[Unknown macro]%s", part->text);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
value = rc_evaluate_value(&part->value, peek, peek_ud, L);
|
value = rc_evaluate_value(&part->value, peek, peek_ud, L);
|
||||||
chars = rc_format_value(ptr, buffersize, value, part->display_type);
|
chars = rc_format_value(ptr, buffersize, value, part->display_type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user