Skip to content

Commit 99e7b43

Browse files
committed
lyb BUGFIX big-endian fixes
Refs #2455
1 parent 15a9cea commit 99e7b43

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/parser_lyb.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,10 @@ lyb_parse_node(struct lyd_lyb_ctx *lybctx, struct lyd_node *parent, struct lyd_n
14251425
char *mod_name = NULL, mod_rev[LY_REV_SIZE];
14261426

14271427
/* read node type */
1428-
lyb_read((uint64_t *)&lyb_type, LYB_NODE_TYPE_BITS, lybctx->parse_ctx);
1428+
lyb_read(&lyb_type, LYB_NODE_TYPE_BITS, lybctx->parse_ctx);
1429+
1430+
/* correct byte order */
1431+
lyb_type = le32toh(lyb_type);
14291432

14301433
switch (lyb_type) {
14311434
case LYB_NODE_END:
@@ -1543,6 +1546,9 @@ lyb_parse_header(struct lyd_lyb_ctx *lybctx)
15431546
data_hash = 0;
15441547
lyb_read((uint8_t *)&data_hash, LYB_HEADER_CTX_HASH_BITS, pctx);
15451548

1549+
/* correct byte order */
1550+
data_hash = le32toh(data_hash);
1551+
15461552
if (!data_hash) {
15471553
/* fine for no data */
15481554
pctx->empty_hash = 1;

src/printer_lyb.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ lyb_write_count(uint32_t count, struct lylyb_print_ctx *lybctx)
447447
return LY_EINT;
448448
}
449449

450-
/* correct byte order */
451-
count = htole32(count);
452-
453450
/* copy count to buf */
454451
buf |= count << prefix_b;
455452

453+
/* correct byte order */
454+
buf = htole32(buf);
455+
456456
return lyb_write(&buf, prefix_b + num_b, lybctx);
457457
}
458458

@@ -492,12 +492,12 @@ lyb_write_size(uint32_t size, struct lylyb_print_ctx *lybctx)
492492
num_b = 32;
493493
}
494494

495-
/* correct byte order */
496-
size = htole32(size);
497-
498495
/* copy size to buf */
499496
buf |= size << prefix_b;
500497

498+
/* correct byte order */
499+
buf = htole32(buf);
500+
501501
return lyb_write(&buf, prefix_b + num_b, lybctx);
502502
}
503503

@@ -635,6 +635,9 @@ lyb_print_header(struct lylyb_print_ctx *lybctx)
635635
/* context hash (is truncated), if not printing empty data */
636636
if (lybctx->ctx) {
637637
hash = lyb_truncate_hash_nonzero(ly_ctx_get_modules_hash(lybctx->ctx), LYB_HEADER_CTX_HASH_BITS);
638+
639+
/* correct byte order */
640+
hash = htole32(hash);
638641
} else {
639642
hash = 0;
640643
}
@@ -1019,6 +1022,9 @@ lyb_print_lyb_type(const struct lyd_node *node, struct lylyb_print_ctx *lybctx)
10191022
lyb_type = LYB_NODE_CHILD;
10201023
}
10211024

1025+
/* correct byte order */
1026+
lyb_type = htole32(lyb_type);
1027+
10221028
LY_CHECK_RET(lyb_write(&lyb_type, LYB_NODE_TYPE_BITS, lybctx));
10231029

10241030
return LY_SUCCESS;

0 commit comments

Comments
 (0)