]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/applayer: return -1 if event info was not found
authorJason Ish <jason.ish@oisf.net>
Fri, 1 Nov 2024 15:32:12 +0000 (09:32 -0600)
committerVictor Julien <victor@inliniac.net>
Fri, 8 Nov 2024 11:06:12 +0000 (12:06 +0100)
The returned event_id was being set to -1, but the function wasn't
returning -1 to indicate error.

Ticket: #7361

rust/src/applayer.rs

index 113aa238b370231aa7dd5c204accbe4e1f9b6536..551a125d979461b2a5b038a48edefddfe04d4cab 100644 (file)
@@ -615,13 +615,13 @@ pub unsafe fn get_event_info<T: AppLayerEvent>(
         return -1;
     }
 
-    let event = match CStr::from_ptr(event_name).to_str().map(T::from_string) {
-        Ok(Some(event)) => event.as_i32(),
-        _ => -1,
-    };
-    *event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
-    *event_id = event as std::os::raw::c_int;
-    return 0;
+    if let Ok(Some(event)) = CStr::from_ptr(event_name).to_str().map(T::from_string) {
+        *event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
+        *event_id = event.as_i32() as std::os::raw::c_int;
+        0
+    } else {
+        -1
+    }
 }
 
 /// Generic `get_info_info_by_id` implementation for enums implementing