public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] printenv show garbage on out-of-memory conditions
@ 2012-09-28 15:00 Maxime Larocque
  2013-04-17 15:36 ` [U-Boot] " Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Larocque @ 2012-09-28 15:00 UTC (permalink / raw)
  To: u-boot

Hello,

In common/cmd_nvedit.c, en env_print(), the wrong type is used for len. hexport_r() returns -1 on error (like OOM), which is converted to 0xffffffff when put in an unsigned. Said value is obviously bigger then 0, and as a result an uninitialized string is then displayed. Other usages of hexport_r() in the code correctly uses ssize_t to keep its return value.

Does not seem to be critical, but it is misleading when debugging a OOM error...

I have added a printf to display something in case of error; I'll leave it to the committer to keep it or remove it.

Found in U-Boot 2011.12, but still present in current git.

Maxime Larocque

Signed-off-by: Maxime Larocque <maxmtl2002@yahoo.ca>
--- common/cmd_nvedit.c
+++ common/cmd_nvedit.c
@@ -110,7 +110,7 @@
  static int env_print(char *name)
  {
  	char *res = NULL;
-	size_t len;
+	ssize_t len;
  
  	if (name) {		/* print a single name */
  		ENTRY e, *ep;
@@ -132,6 +132,9 @@
  		free(res);
  		return len;
  	}
+	else {
+		printf("## Error: cannot export environment\n");
+	}
  
  	/* should never happen */
  	return 0;

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

* [U-Boot] printenv show garbage on out-of-memory conditions
  2012-09-28 15:00 [U-Boot] [PATCH] printenv show garbage on out-of-memory conditions Maxime Larocque
@ 2013-04-17 15:36 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2013-04-17 15:36 UTC (permalink / raw)
  To: u-boot

On Fri, Sep 28, 2012 at 05:00:13AM -0000, Maxime Larocque wrote:

> Hello,
> 
> In common/cmd_nvedit.c, en env_print(), the wrong type is used for
> len. hexport_r() returns -1 on error (like OOM), which is converted to
> 0xffffffff when put in an unsigned. Said value is obviously bigger
> then 0, and as a result an uninitialized string is then displayed.
> Other usages of hexport_r() in the code correctly uses ssize_t to keep
> its return value.

Applied to u-boot/master, with some minor fixups for application.
Thanks!

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

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

end of thread, other threads:[~2013-04-17 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-28 15:00 [U-Boot] [PATCH] printenv show garbage on out-of-memory conditions Maxime Larocque
2013-04-17 15:36 ` [U-Boot] " Tom Rini

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