Fix: harden remapper filters and agent init guard

- skip empty include/exclude entries in Remapper::shouldRemap to avoid
  calling back() on an empty std::string (undefined behavior)
- null-check new_class_data_len/new_classbytes in JuiceRemapperService
  before writing remapped bytes back to the JVMTI callback
- add Agent::initialized_ guard so init() is a no-op on second call,
  preventing duplicate service instantiation and listeners
This commit is contained in:
xiaozhou233 committed 2026-08-18 16:51:21 +08:00
1 parent 18a923373b
commit ff216aabee
4 files changed
+10 -1

No files matched your search

+5
View File
@@ -69,6 +69,11 @@ namespace JuiceAgent {
spdlog::error("[JuiceAgent] Agent not loaded! Please call preload() first!");
return false;
}
if(initialized_) {
spdlog::warn("[JuiceAgent] Agent already initialized! Skipping...");
return true;
}
initialized_ = true;
// Add Abilities
jvmtiCapabilities caps{};
+1
View File
@@ -13,6 +13,7 @@ namespace JuiceAgent {
JuiceAgent::Config::Config config;
bool loaded = false;
bool initialized_ = false;
public:
// Singleton
static Agent& getInstance();
+2
View File
@@ -198,6 +198,7 @@ public:
std::lock_guard<std::mutex> lock(filterMutex_);
for (const auto& exc : excludes_) {
if (exc.empty()) continue;
if (name == exc) return false;
if (exc.back() == '/' && name.rfind(exc, 0) == 0) return false;
if (name.size() > exc.size() &&
@@ -205,6 +206,7 @@ public:
}
for (const auto& inc : includes_) {
if (inc.empty()) continue;
if (name == inc) return true;
if (inc.back() == '/' && name.rfind(inc, 0) == 0) return true;
if (name.size() > inc.size() &&
@@ -53,7 +53,8 @@ private:
void onClassFileLoadHook(const EventClassFileLoadHook& e) {
if (!e.name || !e.jni_env || !e.jvmti_env ||
!e.classbytes || e.class_data_len <= 0) {
!e.classbytes || e.class_data_len <= 0 ||
!e.new_class_data_len || !e.new_classbytes) {
return;
}