[PATCH 1/1] mvebu: fix end-of-array check

Derek LaHousse derek at seaofdirac.org
Wed Nov 30 19:33:40 CET 2022


Properly seek the end of default_environment variables.

The current algorithm overwrites from the second variable.  This
replacement finds the end of the array of strings.

Stomped variables include "board", "soc", "loadaddr".  These can be
seen on a "env default -a" after patch, but they are not seen with a
version before the patch.

Signed-off-by: Derek LaHousse <derek at seaofdirac.org>
---
 board/Marvell/mvebu_armada-37xx/board.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/board/Marvell/mvebu_armada-37xx/board.c
b/board/Marvell/mvebu_armada-37xx/board.c
index c6ecc323bb..ac29ac5b95 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -100,8 +100,11 @@ int board_late_init(void)
 		return 0;
 
 	/* Find free buffer in default_environment[] for new variables
*/
-	while (*ptr != '\0' && *(ptr+1) != '\0') ptr++;
-	ptr += 2;
+	if (*ptr != '\0') { // Defending against empty default env
+		while ((i = strlen(ptr)) != 0) {
+			ptr += i + 1;
+		}
+	}
 
 	/*
 	 * Ensure that 'env default -a' does not erase permanent MAC
addresses
-- 
2.30.2





More information about the U-Boot mailing list