mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

The buffer returned by dso__demangle_sym() may be NULL, don't segv in strcmp if this happens. Currently this happens for NO_LIBELF=1 builds. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andreas Hindborg <a.hindborg@kernel.org> Cc: Benno Lossin <benno.lossin@proton.me> Cc: Björn Roy Baron <bjorn3_gh@protonmail.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Danilo Krummrich <dakr@kernel.org> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Gary Guo <gary@garyguo.net> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Cc: Trevor Gross <tmgross@umich.edu> Cc: Weilin Wang <weilin.wang@intel.com> Link: https://lore.kernel.org/r/20250528032637.198960-3-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
49 lines
1.5 KiB
C
49 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <linux/kernel.h>
|
|
#include "debug.h"
|
|
#include "symbol.h"
|
|
#include "tests.h"
|
|
|
|
static int test__demangle_java(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
int ret = TEST_OK;
|
|
char *buf = NULL;
|
|
size_t i;
|
|
|
|
struct {
|
|
const char *mangled, *demangled;
|
|
} test_cases[] = {
|
|
{ "Ljava/lang/StringLatin1;equals([B[B)Z",
|
|
"java.lang.StringLatin1.equals(byte[], byte[])" },
|
|
{ "Ljava/util/zip/ZipUtils;CENSIZ([BI)J",
|
|
"java.util.zip.ZipUtils.CENSIZ(byte[], int)" },
|
|
{ "Ljava/util/regex/Pattern$BmpCharProperty;match(Ljava/util/regex/Matcher;ILjava/lang/CharSequence;)Z",
|
|
"java.util.regex.Pattern$BmpCharProperty.match(java.util.regex.Matcher, int, java.lang.CharSequence)" },
|
|
{ "Ljava/lang/AbstractStringBuilder;appendChars(Ljava/lang/String;II)V",
|
|
"java.lang.AbstractStringBuilder.appendChars(java.lang.String, int, int)" },
|
|
{ "Ljava/lang/Object;<init>()V",
|
|
"java.lang.Object<init>()" },
|
|
};
|
|
|
|
for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
|
|
buf = dso__demangle_sym(/*dso=*/NULL, /*kmodule=*/0, test_cases[i].mangled);
|
|
if (!buf) {
|
|
pr_debug("FAILED to demangle: \"%s\"\n \"%s\"\n", test_cases[i].mangled,
|
|
test_cases[i].demangled);
|
|
continue;
|
|
}
|
|
if (strcmp(buf, test_cases[i].demangled)) {
|
|
pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
|
|
buf, test_cases[i].demangled);
|
|
ret = TEST_FAIL;
|
|
}
|
|
free(buf);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
DEFINE_SUITE("Demangle Java", demangle_java);
|