Commit 014a9fcd2ebb730004a2bf63e1709369bc587ce8

Authored by Alexander Polleti
Committed by Stéphane Raimbault
1 parent 54c0923c

test the protocol id for 0

previous test would fail if one byte was non zero.
Showing 1 changed file with 4 additions and 2 deletions
src/modbus-tcp.c
... ... @@ -188,6 +188,7 @@ static int _modbus_tcp_check_integrity(modbus_t *ctx, uint8_t *msg, const int ms
188 188 static int _modbus_tcp_pre_check_confirmation(modbus_t *ctx, const uint8_t *req,
189 189 const uint8_t *rsp, int rsp_length)
190 190 {
  191 + unsigned int protocol_id;
191 192 /* Check transaction ID */
192 193 if (req[0] != rsp[0] || req[1] != rsp[1]) {
193 194 if (ctx->debug) {
... ... @@ -199,10 +200,11 @@ static int _modbus_tcp_pre_check_confirmation(modbus_t *ctx, const uint8_t *req,
199 200 }
200 201  
201 202 /* Check protocol ID */
202   - if (rsp[2] != 0x0 && rsp[3] != 0x0) {
  203 + protocol_id = (rsp[2] << 8) + rsp[3];
  204 + if (protocol_id != 0x0) {
203 205 if (ctx->debug) {
204 206 fprintf(stderr, "Invalid protocol ID received 0x%X (not 0x0)\n",
205   - (rsp[2] << 8) + rsp[3]);
  207 + protocol_id);
206 208 }
207 209 errno = EMBBADDATA;
208 210 return -1;
... ...