mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] globalvar: fix crash if CONFIG_NVVAR is not set
@ 2018-12-12 12:01 Antony Pavlov
  2018-12-13  7:06 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Antony Pavlov @ 2018-12-12 12:01 UTC (permalink / raw)
  To: barebox

At the moment globalvar code tries to use nv_device
even if nv_device is not registered.

How to reproduce the problem:

    barebox$ make sandbox_defconfig
    ...
    barebox$ sed -i "s/\(CONFIG_NVVAR\)=y/# \1 is not set/" .config
    barebox$ sed -i "s/\(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW\)=y/# \1 is not set\n# CONFIG_DEFAULT_ENVIRONMENT_GENERIC is not set/" .config
    barebox$ make oldconfig
    ...
    barebox$ make
    ...
    barebox$ ./barebox
    Segmentation fault

This patch blocks nv_device use if CONFIG_NVVAR is not set.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 common/globalvar.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/common/globalvar.c b/common/globalvar.c
index b9bfce7dac..1bea7425d4 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -99,6 +99,9 @@ void dev_param_init_from_nv(struct device_d *dev, const char *name)
 	const char *val;
 	int ret = 0;
 
+	if (!IS_ENABLED(CONFIG_NVVAR))
+		return;
+
 	if (dev == &nv_device)
 		return;
 	if (dev == &global_device)
@@ -138,6 +141,9 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
 	const char *dot;
 	int dotpos;
 
+	if (!IS_ENABLED(CONFIG_NVVAR))
+		return -ENOSYS;
+
 	*dev = NULL;
 
 	if (strncmp(name, "dev.", 4))
@@ -447,6 +453,9 @@ static void globalvar_nv_sync(const char *name)
 {
 	const char *val;
 
+	if (!IS_ENABLED(CONFIG_NVVAR))
+		return;
+
 	val = dev_get_param(&nv_device, name);
 	if (val)
 		dev_set_param(&global_device, name, val);
-- 
2.20.0.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] globalvar: fix crash if CONFIG_NVVAR is not set
  2018-12-12 12:01 [PATCH] globalvar: fix crash if CONFIG_NVVAR is not set Antony Pavlov
@ 2018-12-13  7:06 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2018-12-13  7:06 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Wed, Dec 12, 2018 at 03:01:03PM +0300, Antony Pavlov wrote:
> At the moment globalvar code tries to use nv_device
> even if nv_device is not registered.
> 
> How to reproduce the problem:
> 
>     barebox$ make sandbox_defconfig
>     ...
>     barebox$ sed -i "s/\(CONFIG_NVVAR\)=y/# \1 is not set/" .config
>     barebox$ sed -i "s/\(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW\)=y/# \1 is not set\n# CONFIG_DEFAULT_ENVIRONMENT_GENERIC is not set/" .config
>     barebox$ make oldconfig
>     ...
>     barebox$ make
>     ...
>     barebox$ ./barebox
>     Segmentation fault
> 
> This patch blocks nv_device use if CONFIG_NVVAR is not set.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2018-12-13  7:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 12:01 [PATCH] globalvar: fix crash if CONFIG_NVVAR is not set Antony Pavlov
2018-12-13  7:06 ` Sascha Hauer

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