Skip to content

Commit dc82752

Browse files
authored
fix: guard normalized class name length in dump lookup
1 parent c44aef9 commit dc82752

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

ddprof-lib/src/main/cpp/flightRecorder.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ void Lookup::fillJavaMethodInfo(MethodInfo *mi, jmethodID method,
200200
readable = probe(class_name) & probe(method_name) & probe(method_sig);
201201
}
202202
if (readable) {
203+
const size_t class_name_len = strnlen(class_name, 65536);
204+
const char* normalized_class_name =
205+
class_name_len >= 2 ? class_name + 1 : "";
206+
const size_t normalized_class_name_len =
207+
class_name_len >= 2 ? class_name_len - 2 : 0;
203208

204209
if (first_time) {
205210
jvmtiError line_table_error = jvmti->GetLineNumberTable(method, &line_number_table_size,
@@ -303,13 +308,13 @@ void Lookup::fillJavaMethodInfo(MethodInfo *mi, jmethodID method,
303308
} else {
304309
// don't recognise the suffix, so don't normalise
305310
class_name_id = _classes->lookupDuringDump(
306-
class_name + 1, strnlen(class_name, 65536) - 2);
311+
normalized_class_name, normalized_class_name_len);
307312
}
308313
method_name_id = _symbols.lookup(method_name);
309314
method_sig_id = _symbols.lookup(method_sig);
310315
} else {
311-
class_name_id = _classes->lookupDuringDump(class_name + 1,
312-
strnlen(class_name, 65536) - 2);
316+
class_name_id = _classes->lookupDuringDump(normalized_class_name,
317+
normalized_class_name_len);
313318
method_name_id = _symbols.lookup(method_name);
314319
method_sig_id = _symbols.lookup(method_sig);
315320
}

0 commit comments

Comments
 (0)