Skip to contentSkip to conversation

dcssblk.c : Array index 'i' is used before limits check.

PATCH In review Ameen Ali 2 participants 2 messages Feb 24, 2015 s390

lore
Share & tools
lore

Ameen Ali

author
#0 lore raw

PATCH 1/1 dcssblk.c : Array index 'i' is used before limits check.

---
 drivers/s390/block/dcssblk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/block/dcssblk.c +1 -1
index 96128cb..da21281 100644
@@ -547,7 +547,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
 	 * parse input
 	 */
 	num_of_segments = 0;
-	for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) {
+	for (i = 0; (i < count && (buf[i] != '\0') && (buf[i] != '\n')); i++) {
 		for (j = i; (buf[j] != ':') &&
 			(buf[j] != '\0') &&
 			(buf[j] != '\n') &&
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Ameen Ali

Can you include some text in the commit message body explaining the meaning of the change? (For example 'avoid out-of-bounds-read by checking count before indexing' or something like that?)

Thanks!

-Kees

Quoted 20 lines
---
 drivers/s390/block/dcssblk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/block/dcssblk.c +1 -2
index 96128cb..da21281 100644
@@ -547,7 +547,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
         * parse input
         */
        num_of_segments = 0;
-       for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) {
+       for (i = 0; (i < count && (buf[i] != '\0') && (buf[i] != '\n')); i++) {
                for (j = i; (buf[j] != ':') &&
                        (buf[j] != '\0') &&
                        (buf[j] != '\n') &&
--

2.1.0

Signature · 2 lines
Kees Cook
Chrome OS Security