[PATCH] commands: loady: fix bug with netconsole

Robert Jarzmik robert.jarzmik at free.fr
Thu Jan 1 12:04:21 PST 2015


Netconsole doesn't have a baudrate. Loady supposes a console has one,
and tries to compute the console's baudrate variable value, regardless
of its existence.

This triggers a NULL pointer dereference on netconsole. If attempting
loady on a netconsole is a bit useless, barebox should not panic. Fix
this by checking the variable exists before reading its value.

Signed-off-by: Robert Jarzmik <robert.jarzmik at free.fr>
---
 commands/loadxy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commands/loadxy.c b/commands/loadxy.c
index df14043..1e65cb6 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -43,10 +43,10 @@
 static int console_change_speed(struct console_device *cdev, int baudrate)
 {
 	int current_baudrate;
+	const char *bstr;
 
-	current_baudrate =
-		(int)simple_strtoul(dev_get_param(&cdev->class_dev,
-						  "baudrate"), NULL, 10);
+	bstr = dev_get_param(&cdev->class_dev, "baudrate");
+	current_baudrate = bstr ? (int)simple_strtoul(bstr, NULL, 10) : 0;
 	if (baudrate && baudrate != current_baudrate) {
 		printf("## Switch baudrate from %d to %d bps and press ENTER ...\n",
 		       current_baudrate, baudrate);
-- 
2.1.0




More information about the barebox mailing list