diff mbox series

zram: correctly handle all next_arg() cases

Message ID 20230103030119.1496358-1-senozhatsky@chromium.org (mailing list archive)
State New
Headers show
Series zram: correctly handle all next_arg() cases | expand

Commit Message

Sergey Senozhatsky Jan. 3, 2023, 3:01 a.m. UTC
When supplied buffer does not have assignment sign
next_arg() sets `val` pointer to NULL, so we cannot
dereference it. Add a NULL pointer test to handle
`param` case, in addition to `*val` test, which
handles cases when param has no value assigned to
it: `param=`.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zram_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e290d6d97047..70c412eb6c1f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1140,7 +1140,7 @@  static ssize_t recomp_algorithm_store(struct device *dev,
 	while (*args) {
 		args = next_arg(args, &param, &val);
 
-		if (!*val)
+		if (!val || !*val)
 			return -EINVAL;
 
 		if (!strcmp(param, "algo")) {
@@ -1824,7 +1824,7 @@  static ssize_t recompress_store(struct device *dev,
 	while (*args) {
 		args = next_arg(args, &param, &val);
 
-		if (!*val)
+		if (!val || !*val)
 			return -EINVAL;
 
 		if (!strcmp(param, "type")) {