Skip to content

Commit 203c888

Browse files
committed
pex: fix endian issues on config transfer
Fixes transferring network config between big-endian and little-endian devices. Please note that on little-endian this makes patched and unpatched devices incompatible to each other, since protocol fields are changed to big-endian. Reported-by: Paul Spooren <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent 12ac684 commit 203c888

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pex-msg.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void pex_msg_update_response_init(struct pex_msg_update_send_ctx *ctx,
365365

366366
res = pex_msg_append(sizeof(*res));
367367
res->req_id = req->req_id;
368-
res->data_len = len;
368+
res->data_len = cpu_to_be32(len);
369369

370370
if (!fread(e_key_priv, sizeof(e_key_priv), 1, pex_urandom))
371371
return;
@@ -400,7 +400,7 @@ bool pex_msg_update_response_continue(struct pex_msg_update_send_ctx *ctx)
400400

401401
res_ext = pex_msg_append(sizeof(*res_ext));
402402
res_ext->req_id = ctx->req_id;
403-
res_ext->offset = ctx->cur - ctx->data;
403+
res_ext->offset = cpu_to_be32(ctx->cur - ctx->data);
404404
pex_msg_update_response_fill(ctx);
405405

406406
return true;
@@ -482,13 +482,13 @@ void *pex_msg_update_response_recv(const void *data, int len, enum pex_opcode op
482482

483483
ctx = pex_msg_update_recv_ctx_get(res->req_id);
484484
if (!ctx || ctx->data_len || !res->data_len ||
485-
res->data_len > UNETD_NET_DATA_SIZE_MAX)
485+
be32_to_cpu(res->data_len) > UNETD_NET_DATA_SIZE_MAX)
486486
return NULL;
487487

488488
data += sizeof(*res);
489489
len -= sizeof(*res);
490490

491-
ctx->data_len = res->data_len;
491+
ctx->data_len = be32_to_cpu(res->data_len);
492492
memcpy(ctx->e_key, res->e_key, sizeof(ctx->e_key));
493493
ctx->data = malloc(ctx->data_len);
494494
} else if (op == PEX_MSG_UPDATE_RESPONSE_DATA) {
@@ -498,7 +498,7 @@ void *pex_msg_update_response_recv(const void *data, int len, enum pex_opcode op
498498
return NULL;
499499

500500
ctx = pex_msg_update_recv_ctx_get(res->req_id);
501-
if (!ctx || ctx->data_ofs != res->offset)
501+
if (!ctx || ctx->data_ofs != be32_to_cpu(res->offset))
502502
return NULL;
503503

504504
data += sizeof(*res);

0 commit comments

Comments
 (0)