summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2024-02-02 11:17:46 -0500
committergit <svn-admin@ruby-lang.org>2024-02-02 16:35:43 +0000
commit8f9d999d5967182b8fafdf6ff47eb4db1358e29b (patch)
tree0b3a6b2264484055a8c9cc8a6b68ae15e1475890
parent31378dc0969f4466b2122d730b7298dd7004acdf (diff)
[ruby/prism] Fix overlapping memcpy
It's UB to use memcpy with overlapping source and destination. This might be causing crashes on 32 bit platforms and on OpenBSD. Use memmove instead. Add a bounds check while we're at it since it's unclear whether one-past-end pointer with n=0 is UB. https://github.com/ruby/prism/commit/719f54ff5e
-rw-r--r--prism/prism.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 87fc43105d..d91f2a69c4 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -18061,7 +18061,9 @@ pm_parser_errors_format_sort(const pm_list_t *error_list, const pm_newline_list_
// Now we're going to shift all of the errors after this one down one
// index to make room for the new error.
- memcpy(&errors[index + 1], &errors[index], sizeof(pm_error_t) * (error_list->size - index - 1));
+ if (index + 1 < error_list->size) {
+ memmove(&errors[index + 1], &errors[index], sizeof(pm_error_t) * (error_list->size - index - 1));
+ }
// Finally, we'll insert the error into the array.
uint32_t column_end;