Skip to contentSkip to conversation

blkmapd: Fix infinite loop when reading serial

PATCH In review Kinglong Mee 2 participants 3 messages May 28, 2015 – Jun 30, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blkmapd: Fix infinite loop when reading serial

If (dev_id->ids & 0xf) < current_id, must updates pos when continue. Otherwise an infinite loop.

No other places use the pos value, just move to the top of while.

---
 utils/blkmapd/device-inq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
utils/blkmapd/device-inq.c +2 -1
index c5bf71f..6b56b67 100644
@@ -196,6 +196,8 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
 
 	while (pos < (len - devid_len)) {
 		dev_id = (struct bl_dev_id *)&(dev_root->data[pos]);
+		pos += (dev_id->len + devid_len);
+
 		if ((dev_id->ids & 0xf) < current_id)
 			continue;
 		switch (dev_id->ids & 0xf) {
@@ -226,7 +228,6 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
 		}
 		if (current_id == 3)
 			break;
-		pos += (dev_id->len + devid_len);
 	}
  out:
 	if (!serial_out)
Signature · 1 line
2.4.1
#1 lore raw

ping...

Quoted 32 lines · Kinglong Mee

If (dev_id->ids & 0xf) < current_id, must updates pos when continue. Otherwise an infinite loop.

No other places use the pos value, just move to the top of while.

---
 utils/blkmapd/device-inq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
utils/blkmapd/device-inq.c +2 -1
index c5bf71f..6b56b67 100644
@@ -196,6 +196,8 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
 
 	while (pos < (len - devid_len)) {
 		dev_id = (struct bl_dev_id *)&(dev_root->data[pos]);
+		pos += (dev_id->len + devid_len);
+
 		if ((dev_id->ids & 0xf) < current_id)
 			continue;
 		switch (dev_id->ids & 0xf) {
@@ -226,7 +228,6 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
 		}
 		if (current_id == 3)
 			break;
-		pos += (dev_id->len + devid_len);
 	}
  out:
 	if (!serial_out)
#2 lore raw
In reply to Kinglong Mee
Quoted 6 lines · Kinglong Mee

If (dev_id->ids & 0xf) < current_id, must updates pos when continue. Otherwise an infinite loop.

No other places use the pos value, just move to the top of while.

Sorry for the delay.... Committed!

steved.

Quoted 26 lines
---
 utils/blkmapd/device-inq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
utils/blkmapd/device-inq.c +2 -1
index c5bf71f..6b56b67 100644
@@ -196,6 +196,8 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
 
 	while (pos < (len - devid_len)) {
 		dev_id = (struct bl_dev_id *)&(dev_root->data[pos]);
+		pos += (dev_id->len + devid_len);
+
 		if ((dev_id->ids & 0xf) < current_id)
 			continue;
 		switch (dev_id->ids & 0xf) {
@@ -226,7 +228,6 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
 		}
 		if (current_id == 3)
 			break;
-		pos += (dev_id->len + devid_len);
 	}
  out:
 	if (!serial_out)