-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[l2]: null-safe type check in ChangeL2NetworkVlanId #3722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,7 @@ public APIMessage intercept(APIMessage msg) throws ApiMessageInterceptionExcepti | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private void validate(APIChangeL2NetworkVlanIdMsg msg) { | ||||||||||||||||||||||||||||
| if (!msg.getType().equals(VxlanNetworkConstant.VXLAN_NETWORK_TYPE)){ | ||||||||||||||||||||||||||||
| if (!VxlanNetworkConstant.VXLAN_NETWORK_TYPE.equals(msg.getType())){ | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+41
to
43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 空
💡 建议修复 private void validate(APIChangeL2NetworkVlanIdMsg msg) {
- if (!VxlanNetworkConstant.VXLAN_NETWORK_TYPE.equals(msg.getType())){
+ String effectiveType = msg.getType();
+ if (effectiveType == null) {
+ effectiveType = Q.New(L2NetworkVO.class)
+ .select(L2NetworkVO_.type)
+ .eq(L2NetworkVO_.uuid, msg.getL2NetworkUuid())
+ .findValue();
+ }
+ if (!VxlanNetworkConstant.VXLAN_NETWORK_TYPE.equals(effectiveType)) {
return;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| if (!NetworkUtils.isValidVni(msg.getVlan())) { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type为空时会落入后续写库路径,存在写入非法类型风险Line 425-433现在不会再因空值抛 NPE,但空type会继续执行到后续链路;同文件Line 545-553会把msg.getType()作为targetType写回L2NetworkVO.type。当type == null时,这里会产生错误状态或数据库异常。💡 建议修复
private void handle(APIChangeL2NetworkVlanIdMsg msg){ APIChangeL2NetworkVlanIdEvent event = new APIChangeL2NetworkVlanIdEvent(msg.getId()); + String effectiveType = msg.getType() == null ? self.getType() : msg.getType(); + if (msg.getType() == null) { + msg.setType(effectiveType); + } + if (msg.getVlan() == null - && L2NetworkConstant.L2_NO_VLAN_NETWORK_TYPE.equals(msg.getType()) + && L2NetworkConstant.L2_NO_VLAN_NETWORK_TYPE.equals(effectiveType) && self.getVirtualNetworkId().equals(0)) { event.setInventory(getSelfInventory()); bus.publish(event); return; } if (msg.getVlan() != null - && L2NetworkConstant.L2_VLAN_NETWORK_TYPE.equals(msg.getType()) + && L2NetworkConstant.L2_VLAN_NETWORK_TYPE.equals(effectiveType) && self.getVirtualNetworkId().equals(msg.getVlan())) { event.setInventory(getSelfInventory()); bus.publish(event); return; }🤖 Prompt for AI Agents