From: Christopher Faulet Date: Fri, 18 May 2018 12:38:56 +0000 (+0200) Subject: BUG/MEDIUM: contrib/mod_defender: Use network order to encode/decode flags X-Git-Tag: v1.9-dev1~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48d02d0d21b7ec85de2a6bbeb85757add52e3dfc;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: contrib/mod_defender: Use network order to encode/decode flags A recent fix on the SPOE revealed a mismatch between the SPOE specification and the mod_defender implementation on the way flags are encoded or decoded. They must be exchanged using the network bytes order and not the host one. Be careful though, this patch breaks the compatiblity with HAProxy SPOE before commit c4dcaff3 ("BUG/MEDIUM: spoe: Flags are not encoded in network order"). --- diff --git a/contrib/mod_defender/spoa.c b/contrib/mod_defender/spoa.c index c4e15bb443..1191260a47 100644 --- a/contrib/mod_defender/spoa.c +++ b/contrib/mod_defender/spoa.c @@ -460,6 +460,7 @@ handle_hahello(struct spoe_frame *frame) /* Retrieve flags */ memcpy((char *)&(frame->flags), p, 4); + frame->flags = ntohl(frame->flags); p += 4; /* Fragmentation is not supported for HELLO frame */ @@ -567,6 +568,7 @@ handle_hadiscon(struct spoe_frame *frame) /* Retrieve flags */ memcpy((char *)&(frame->flags), p, 4); + frame->flags = ntohl(frame->flags); p += 4; /* Fragmentation is not supported for DISCONNECT frame */ @@ -648,6 +650,7 @@ handle_hanotify(struct spoe_frame *frame) /* Retrieve flags */ memcpy((char *)&(frame->flags), p, 4); + frame->flags = ntohl(frame->flags); p += 4; /* Fragmentation is not supported */ @@ -710,6 +713,7 @@ handle_hafrag(struct spoe_frame *frame) /* Retrieve flags */ memcpy((char *)&(frame->flags), p, 4); + frame->flags = ntohl(frame->flags); p+= 4; /* Read the stream-id and frame-id */ @@ -772,6 +776,7 @@ prepare_agenthello(struct spoe_frame *frame) *p++ = SPOE_FRM_T_AGENT_HELLO; /* Set flags */ + flags = htonl(flags); memcpy(p, (char *)&flags, 4); p += 4; @@ -853,6 +858,7 @@ prepare_agentdicon(struct spoe_frame *frame) *p++ = SPOE_FRM_T_AGENT_DISCON; /* Set flags */ + flags = htonl(flags); memcpy(p, (char *)&flags, 4); p += 4; @@ -900,6 +906,7 @@ prepare_agentack(struct spoe_frame *frame) *p++ = SPOE_FRM_T_AGENT_ACK; /* Set flags */ + flags = htonl(flags); memcpy(p, (char *)&flags, 4); p += 4;