mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] state: backend_bucket_circular: fix old state reads
@ 2017-07-18 13:14 Philipp Zabel
  0 siblings, 0 replies; only message in thread
From: Philipp Zabel @ 2017-07-18 13:14 UTC (permalink / raw)
  To: barebox

When the circular bucket meta magic was not found, it is assumed that
the whole written state is in the old on-storage format. In that case,
the size of the circular bucket meta must not be subtracted from the
read length, or the (complete_len > len) check in the raw backend's
verify function will fail:

    state: Error, invalid data_len 16 in header, have data of len 24

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 common/state/backend_bucket_circular.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c
index 7c81cdfaf..3dcff5cf0 100644
--- a/common/state/backend_bucket_circular.c
+++ b/common/state/backend_bucket_circular.c
@@ -279,7 +279,10 @@ static int state_backend_bucket_circular_read(struct state_backend_storage_bucke
 	}
 
 	*buf_out = buf;
-	*len_out = read_len - sizeof(struct state_backend_storage_bucket_circular_meta);
+	/* When reading old state there is no circular bucket metadata */
+	if (circ->last_written_length)
+		read_len -= sizeof(struct state_backend_storage_bucket_circular_meta);
+	*len_out = read_len;
 
 	return ret;
 }
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-18 13:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-18 13:14 [PATCH] state: backend_bucket_circular: fix old state reads Philipp Zabel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox