fix: prevent NPE in AlertType #2371
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe
I found potential memory safety and stability issues in the Cat codebase:
CWE-476 (NULL Pointer Dereference):
In several parts of the Cat project, such as calls to
AlertType.getTypeByName(), an unknown alert type name could cause the method to returnnull.If the returned value is used directly without a null check (e.g., calling
.getName()or.getTitle()), this could lead to a NullPointerException and result in a crash or undefined behavior.Expected behavior
AlertType.getTypeByName()should always return a validAlertTypeinstance.AlertType.Unknown, notnull.Actual behavior
getTypeByName()returnednull.alert.getType().getName()), a NullPointerException would occur at runtime, potentially causing a crash.How to Reproduce
AlertType.getTypeByName("SOME_INVALID_TYPE").null..getName()or.getTitle()on the returned value without a null check.Patch
This patch adds an
Unknownenum value toAlertTypeand modifiesgetTypeByName()to returnAlertType.Unknowninstead ofnullwhen the type name is unrecognized.This change ensures that a valid enum value is always returned, preventing null pointer dereference vulnerabilities.