rust/applayer: use correct return type for Parser

The mismatch between the types would randomly lead to the return code
of the Rust parser to be not correctly handled over the C/Rust
boundary. This would lead to the API considering a parser to be in
error state when it was not.
pull/3496/head
Victor Julien 7 years ago
parent efbb5ce0fe
commit ae10a92bc6

@ -301,7 +301,7 @@ pub extern "C" fn rs_template_parse_request(
input_len: u32,
_data: *const libc::c_void,
_flags: u8,
) -> i8 {
) -> i32 {
let eof = unsafe {
if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF) > 0 {
true
@ -331,7 +331,7 @@ pub extern "C" fn rs_template_parse_response(
input_len: u32,
_data: *const libc::c_void,
_flags: u8,
) -> i8 {
) -> i32 {
let _eof = unsafe {
if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF) > 0 {
true

@ -278,7 +278,7 @@ pub extern "C" fn rs_dhcp_parse(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let state = cast_pointer!(state, DHCPState);
let buf = build_slice!(input, input_len as usize);
if state.parse(buf) {

@ -126,7 +126,7 @@ impl IKEV2State {
/// Parse an IKEV2 request message
///
/// Returns The number of messages parsed, or -1 on error
fn parse(&mut self, i: &[u8], direction: u8) -> i8 {
fn parse(&mut self, i: &[u8], direction: u8) -> i32 {
match parse_ikev2_header(i) {
IResult::Done(rem,ref hdr) => {
if rem.len() == 0 && hdr.length == 28 {
@ -444,7 +444,7 @@ pub extern "C" fn rs_ikev2_parse_request(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,IKEV2State);
state.parse(buf, STREAM_TOSERVER)
@ -457,7 +457,7 @@ pub extern "C" fn rs_ikev2_parse_response(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,IKEV2State);
let res = state.parse(buf, STREAM_TOCLIENT);

@ -105,7 +105,7 @@ impl KRB5State {
/// Parse a Kerberos request message
///
/// Returns The number of messages parsed, or -1 on error
fn parse(&mut self, i: &[u8], _direction: u8) -> i8 {
fn parse(&mut self, i: &[u8], _direction: u8) -> i32 {
match der_read_element_header(i) {
IResult::Done(_rem,hdr) => {
// Kerberos messages start with an APPLICATION header
@ -462,7 +462,7 @@ pub extern "C" fn rs_krb5_parse_request(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,KRB5State);
state.parse(buf, STREAM_TOSERVER)
@ -475,7 +475,7 @@ pub extern "C" fn rs_krb5_parse_response(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,KRB5State);
state.parse(buf, STREAM_TOCLIENT)
@ -488,7 +488,7 @@ pub extern "C" fn rs_krb5_parse_request_tcp(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
if input_len < 4 { return -1; }
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,KRB5State);
@ -546,7 +546,7 @@ pub extern "C" fn rs_krb5_parse_response_tcp(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
if input_len < 4 { return -1; }
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,KRB5State);

@ -85,7 +85,7 @@ impl NTPState {
/// Parse an NTP request message
///
/// Returns The number of messages parsed, or -1 on error
fn parse(&mut self, i: &[u8], _direction: u8) -> i8 {
fn parse(&mut self, i: &[u8], _direction: u8) -> i32 {
match parse_ntp(i) {
IResult::Done(_,ref msg) => {
// SCLogDebug!("parse_ntp: {:?}",msg);
@ -196,7 +196,7 @@ pub extern "C" fn rs_ntp_parse_request(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,NTPState);
state.parse(buf, 0)
@ -209,7 +209,7 @@ pub extern "C" fn rs_ntp_parse_response(_flow: *const core::Flow,
input: *const libc::uint8_t,
input_len: u32,
_data: *const libc::c_void,
_flags: u8) -> i8 {
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,NTPState);
state.parse(buf, 1)

@ -124,7 +124,7 @@ pub type ParseFn = extern "C" fn (flow: *const Flow,
input: *const u8,
input_len: u32,
data: *const c_void,
flags: u8) -> i8;
flags: u8) -> i32;
pub type ProbeFn = extern "C" fn (flow: *const Flow,input:*const u8, input_len: u32) -> AppProto;
pub type StateAllocFn = extern "C" fn () -> *mut c_void;
pub type StateFreeFn = extern "C" fn (*mut c_void);

Loading…
Cancel
Save