Skip to content

Commit f30c3ae

Browse files
authored
Merge branch 'master' into dependabot/github_actions/gh-actions-packages-da5bf40e92
2 parents a6a2bd3 + 10faebc commit f30c3ae

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ext/datadog_profiling_native_extension/private_vm_api_access.c

+8
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ VALUE thread_name_for(VALUE thread) {
312312
// to support our custom rb_profile_frames (see below)
313313
// Modifications:
314314
// * Support int first_lineno for Ruby 3.2.0+ (https://github.com/ruby/ruby/pull/6430)
315+
// * Validate iseq and pos before calling `rb_iseq_line_no` as a safety measure (see comment below for details)
315316
//
316317
// `node_id` gets used depending on Ruby VM compilation settings (USE_ISEQ_NODE_ID being defined).
317318
// To avoid getting false "unused argument" warnings in setups where it's not used, we need to do this weird dance
@@ -358,6 +359,13 @@ calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id)
358359
__builtin_trap();
359360
}
360361
#endif
362+
363+
// In PROF-11475 we spotted a crash when calling `rb_iseq_line_no` from this method. We couldn't reproduce or
364+
// figure out the root cause, but "just in case", we're validating that the iseq looks valid and that the
365+
// `n` used for the position is also sane, and if they don't look good, we don't calculate the line, rather
366+
// than potentially trigger any issues.
367+
if (RB_UNLIKELY(!RB_TYPE_P((VALUE) iseq, T_IMEMO) || n < 0 || n > ISEQ_BODY(iseq)->iseq_size)) return 0;
368+
361369
if (lineno) *lineno = rb_iseq_line_no(iseq, pos);
362370
#ifdef USE_ISEQ_NODE_ID
363371
if (node_id) *node_id = rb_iseq_node_id(iseq, pos);

0 commit comments

Comments
 (0)