All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] Patch to mkenvimage to handle text files with length that exceed env size
@ 2015-03-12 15:52 Brian McFarland
  2015-03-17 19:08 ` [U-Boot] [PATCH] mkenvimage: Handle " Joe Hershberger
  2015-03-28 18:10 ` [U-Boot] Patch to mkenvimage to handle " Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Brian McFarland @ 2015-03-12 15:52 UTC (permalink / raw)
  To: u-boot

The current head revision of mkenvimage
(e72be8947e129f5ab274c0a9f235d2cc0014b2ea) will prevent you from creating
an env image from a text file that is larger than the env length specified
by the '-s' option.  That doesn't make sense given that the tool now allows
comments and blank lines.  This patch removes that limitation and allows
longer text files to be used.

I don't have time / desire at the moment to figure out "patman" and could
really care less if this is adopted up stream.  Just figured I would share
in case anybody else finds it useful enough to take time to do a proper
patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_mkenvimage_input_length_limit.patch
Type: text/x-patch
Size: 2426 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150312/593765ea/attachment.bin>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] mkenvimage: Handle text files with length that exceed env size
  2015-03-12 15:52 [U-Boot] Patch to mkenvimage to handle text files with length that exceed env size Brian McFarland
@ 2015-03-17 19:08 ` Joe Hershberger
  2015-03-28 18:10 ` [U-Boot] Patch to mkenvimage to handle " Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Hershberger @ 2015-03-17 19:08 UTC (permalink / raw)
  To: u-boot

From: Brian McFarland <bmcfarland@rldrake.com>

The current head revision of mkenvimage
(e72be8947e129f5ab274c0a9f235d2cc0014b2ea) will prevent you from
creating an env image from a text file that is larger than the env
length specified by the '-s' option.  That doesn't make sense given that
the tool now allows comments and blank lines.  This patch removes that
limitation and allows longer text files to be used.

Signed-off-by: Brian McFarland <bmcfarland@rldrake.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---

Converted to a proper patch for the mailing list to be able to process.

 tools/mkenvimage.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
index 6971b91..f1f602a 100644
--- a/tools/mkenvimage.c
+++ b/tools/mkenvimage.c
@@ -214,14 +214,13 @@ int main(int argc, char **argv)
 		}
 		ret = close(txt_fd);
 	}
-	/* The +1 is for the additionnal ending \0. See below. */
-	if (filesize + 1 > envsize) {
-		fprintf(stderr, "The input file is larger than the environment partition size\n");
-		return EXIT_FAILURE;
-	}
 
-	/* Replace newlines separating variables with \0 */
-	for (fp = 0, ep = 0 ; fp < filesize ; fp++) {
+	/*
+	 * Parse one byte@a time until reaching the end of the file OR until
+	 * the environment fills up. Check ep against envsize - 1 to allow for
+	 * an extra trailing '\0'.
+	 */
+	for (fp = 0, ep = 0 ; fp < filesize && ep < envsize - 1; fp++) {
 		if (filebuf[fp] == '\n') {
 			if (fp == 0 || filebuf[fp-1] == '\n') {
 				/*
@@ -250,6 +249,27 @@ int main(int argc, char **argv)
 		}
 	}
 	/*
+	 * If there are more bytes in the file still, it means the env filled up
+	 * before parsing the whole file.  Eat comments & whitespace here to see
+	 * if there was anything meaningful left in the file, and if so, throw
+	 * an error and exit.
+	 */
+	for (; fp < filesize; fp++) {
+		if (filebuf[fp] == '\n') {
+			if (fp == 0 || filebuf[fp-1] == '\n') {
+				/* Ignore blank lines */
+				continue;
+			}
+		} else if ((fp == 0 || filebuf[fp-1] == '\n') &&
+			   filebuf[fp] == '#') {
+			while (++fp < filesize && filebuf[fp] != '\n')
+				continue;
+		} else {
+			fprintf(stderr, "The environment file is too large for the target environment storage\n");
+			return EXIT_FAILURE;
+		}
+	}
+	/*
 	 * Make sure there is a final '\0'
 	 * And do it again on the next byte to mark the end of the environment.
 	 */
-- 
1.7.11.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] Patch to mkenvimage to handle text files with length that exceed env size
  2015-03-12 15:52 [U-Boot] Patch to mkenvimage to handle text files with length that exceed env size Brian McFarland
  2015-03-17 19:08 ` [U-Boot] [PATCH] mkenvimage: Handle " Joe Hershberger
@ 2015-03-28 18:10 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2015-03-28 18:10 UTC (permalink / raw)
  To: u-boot

On Thu, Mar 12, 2015 at 11:52:49AM -0400, Brian McFarland wrote:

> The current head revision of mkenvimage
> (e72be8947e129f5ab274c0a9f235d2cc0014b2ea) will prevent you from creating
> an env image from a text file that is larger than the env length specified
> by the '-s' option.  That doesn't make sense given that the tool now allows
> comments and blank lines.  This patch removes that limitation and allows
> longer text files to be used.
> 
> I don't have time / desire at the moment to figure out "patman" and could
> really care less if this is adopted up stream.  Just figured I would share
> in case anybody else finds it useful enough to take time to do a proper
> patch.
> 
> >From 39ff30190c2bf687861f4b4b33230f1944fb64f9 Mon Sep 17 00:00:00 2001
> From: Brian McFarland <bmcfarland@rldrake.com>
> Date: Thu, 12 Mar 2015 11:37:19 -0400
> Subject: [PATCH] In mkenvimage, removed the check that prevented using a
>  source text file larger than the output environment image.  Instead, the main
>  parsing loop checks to see if the environment buffer is full, and quits if it
>  is.  After the main parse loop, a second loop swallows comments and
>  whitespace until either the EOF is reached or more env vars are found, in
>  which case an error will be thrown.
> 

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150328/a0de2341/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-28 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 15:52 [U-Boot] Patch to mkenvimage to handle text files with length that exceed env size Brian McFarland
2015-03-17 19:08 ` [U-Boot] [PATCH] mkenvimage: Handle " Joe Hershberger
2015-03-28 18:10 ` [U-Boot] Patch to mkenvimage to handle " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.