mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
prevent buffer overflow when encountering an unknown macro
This commit is contained in:
parent
a1951b51b6
commit
8baf0f6340
@ -666,7 +666,7 @@ static int rcheevos_parse(const char* json)
|
||||
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);
|
||||
if (buffer_size <= 0)
|
||||
@ -681,8 +681,8 @@ static int rcheevos_parse(const char* json)
|
||||
}
|
||||
else
|
||||
{
|
||||
char *buffer = (char*)malloc(buffer_size);
|
||||
rcheevos_locals.richpresence.richpresence = rc_parse_richpresence(buffer, rcheevos_locals.patchdata.richpresence_script, NULL, 0);
|
||||
char *rp_buffer = (char*)malloc(buffer_size);
|
||||
rcheevos_locals.richpresence.richpresence = rc_parse_richpresence(rp_buffer, rcheevos_locals.patchdata.richpresence_script, NULL, 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 */
|
||||
enum {
|
||||
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) {
|
||||
@ -161,10 +162,15 @@ static rc_richpresence_display_t* rc_parse_richpresence_display_internal(const c
|
||||
*next = part;
|
||||
next = &part->next;
|
||||
|
||||
ptr = line;
|
||||
/* find the closing parenthesis */
|
||||
while (ptr < endline && *ptr != ')')
|
||||
++ptr;
|
||||
if (*ptr == ')')
|
||||
++ptr;
|
||||
|
||||
part->display_type = RC_FORMAT_STRING;
|
||||
part->text = rc_alloc_str(parse, "[Unknown macro]", 15);
|
||||
/* assert: the allocated string is going to be smaller than the memory used for the parameter of the macro */
|
||||
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;
|
||||
|
||||
case RC_FORMAT_UNKNOWN_MACRO:
|
||||
chars = snprintf(ptr, buffersize, "[Unknown macro]%s", part->text);
|
||||
break;
|
||||
|
||||
default:
|
||||
value = rc_evaluate_value(&part->value, peek, peek_ud, L);
|
||||
chars = rc_format_value(ptr, buffersize, value, part->display_type);
|
||||
|
Loading…
x
Reference in New Issue
Block a user