fix: guard null const char* and out-of-bounds vector access in LOG_INFO calls

cerebellum_hooks.cpp (ConfigureDualArmHooks):
- Pass `action ? action : "unknown"` to LOG_INFO to avoid fmt crash
  when motion_type does not match any known type (null const char*)
- Guard target_joints[0..5] with has_joints check to avoid OOB access
  when the joints vector has fewer than 6 elements

cerebellum_node.cpp (CallInverseKinematics):
- Guard angles[0..5] with has_angles check to avoid OOB access
  if the IK service returns fewer than 6 joint angles
This commit is contained in:
2026-03-04 17:17:57 +08:00
parent 80217bbae7
commit 13f235c682
2 changed files with 10 additions and 4 deletions

View File

@@ -239,7 +239,7 @@ void CerebellumHooks::ConfigureDualArmHooks(CerebellumNode * node)
action = "take_object";
}
LOG_INFO("[{}] param[{}]: action={}, motion_type={}",
skill_name.c_str(), i, action, p.motion_type);
skill_name.c_str(), i, action ? action : "unknown", p.motion_type);
if (action) {
geometry_msgs::msg::Pose pose;
@@ -257,11 +257,14 @@ void CerebellumHooks::ConfigureDualArmHooks(CerebellumNode * node)
: interfaces::msg::ArmMotionParams::MOVEJ;
}
const bool has_joints = p.target_joints.size() >= 6;
LOG_INFO("[{}] param[{}]: arm_id={} motion_type={} blend_radius={} pose=({:.4f}, {:.4f}, {:.4f}, {:.4f}, {:.4f}, {:.4f}, {:.4f}) joint_size={} joints=({:.4f}, {:.4f}, {:.4f}, {:.4f}, {:.4f}, {:.4f})",
skill_name.c_str(), i, p.arm_id, p.motion_type, p.blend_radius,
p.target_pose.position.x, p.target_pose.position.y, p.target_pose.position.z,
p.target_pose.orientation.x, p.target_pose.orientation.y, p.target_pose.orientation.z, p.target_pose.orientation.w, p.target_joints.size(),
p.target_joints[0], p.target_joints[1], p.target_joints[2], p.target_joints[3], p.target_joints[4], p.target_joints[5]);
has_joints ? p.target_joints[0] : 0.0, has_joints ? p.target_joints[1] : 0.0,
has_joints ? p.target_joints[2] : 0.0, has_joints ? p.target_joints[3] : 0.0,
has_joints ? p.target_joints[4] : 0.0, has_joints ? p.target_joints[5] : 0.0);
}
return goal;

View File

@@ -1457,8 +1457,11 @@ int CerebellumNode::CallInverseKinematics(const tf2::Vector3& pos, const tf2::Qu
for (size_t i = 0; i < result->joint_angles.size(); ++i) {
angles[i] = result->joint_angles[i];
}
LOG_INFO("arm_id {} Inverse kinematics service SUCCESS returned angles: [{}, {}, {}, {}, {}, {}]", arm_id,
angles[0], angles[1], angles[2], angles[3], angles[4], angles[5]);
const bool has_angles = angles.size() >= 6;
LOG_INFO("arm_id {} Inverse kinematics service SUCCESS returned angles: [{}, {}, {}, {}, {}, {}]", arm_id,
has_angles ? angles[0] : 0.0, has_angles ? angles[1] : 0.0,
has_angles ? angles[2] : 0.0, has_angles ? angles[3] : 0.0,
has_angles ? angles[4] : 0.0, has_angles ? angles[5] : 0.0);
return 0;
} else {
LOG_ERROR("arm_id {} Inverse kinematics service returned failure: {}", arm_id, result->result);