9
0
Fork 0

common: console: Fix possible null pointer dereference

doing a 'cs0.active=' on the command line crashed barebox. Fix this by
not dereferencing val when it's NULL.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Alexander Shiyan 2013-07-07 16:27:17 +04:00 committed by Sascha Hauer
parent b90bceb6a9
commit 4ccf45db0a
1 changed files with 13 additions and 14 deletions

View File

@ -62,22 +62,21 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
char active[4];
unsigned int flag = 0, i = 0;
if (!val)
dev_param_set_generic(dev, param, NULL);
if (val) {
if (strchr(val, 'i') && cdev->f_caps & CONSOLE_STDIN) {
active[i++] = 'i';
flag |= CONSOLE_STDIN;
}
if (strchr(val, 'i') && cdev->f_caps & CONSOLE_STDIN) {
active[i++] = 'i';
flag |= CONSOLE_STDIN;
}
if (strchr(val, 'o') && cdev->f_caps & CONSOLE_STDOUT) {
active[i++] = 'o';
flag |= CONSOLE_STDOUT;
}
if (strchr(val, 'o') && cdev->f_caps & CONSOLE_STDOUT) {
active[i++] = 'o';
flag |= CONSOLE_STDOUT;
}
if (strchr(val, 'e') && cdev->f_caps & CONSOLE_STDERR) {
active[i++] = 'e';
flag |= CONSOLE_STDERR;
if (strchr(val, 'e') && cdev->f_caps & CONSOLE_STDERR) {
active[i++] = 'e';
flag |= CONSOLE_STDERR;
}
}
active[i] = 0;