Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1338161 > unrolled thread

[PATCH 1/3] lightnvm: fix up nonsensical configure overrun checking

Started byMatias Bjørling <m@bjorling.me>
First post2016-02-19 14:00 +0100
Last post2016-02-19 14:00 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/3] lightnvm: fix up nonsensical configure overrun checking Matias Bjørling <m@bjorling.me> - 2016-02-19 14:00 +0100

#1338161 — [PATCH 1/3] lightnvm: fix up nonsensical configure overrun checking

FromMatias Bjørling <m@bjorling.me>
Date2016-02-19 14:00 +0100
Subject[PATCH 1/3] lightnvm: fix up nonsensical configure overrun checking
Message-ID<r3SP8-5eH-3@gated-at.bofh.it>
From: Alan <gnomes@lxorguk.ukuu.org.uk>

Instead of checking a constant 0 actually check the space available. Even
better remember to allow for the header and also check the right amount of
space is needed.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/lightnvm/core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index c3d4b54..b53632d 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -868,20 +868,19 @@ static int nvm_configure_by_str_event(const char *val,
 
 static int nvm_configure_get(char *buf, const struct kernel_param *kp)
 {
-	int sz = 0;
-	char *buf_start = buf;
+	int sz;
 	struct nvm_dev *dev;
 
-	buf += sprintf(buf, "available devices:\n");
+	sz = sprintf(buf, "available devices:\n");
 	down_write(&nvm_lock);
 	list_for_each_entry(dev, &nvm_devices, devices) {
-		if (sz > 4095 - DISK_NAME_LEN)
+		if (sz > 4095 - DISK_NAME_LEN - 2)
 			break;
-		buf += sprintf(buf, " %32s\n", dev->name);
+		sz += sprintf(buf + sz, " %32s\n", dev->name);
 	}
 	up_write(&nvm_lock);
 
-	return buf - buf_start - 1;
+	return sz;
 }
 
 static const struct kernel_param_ops nvm_configure_by_str_event_param_ops = {
-- 
2.1.4

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web