diff mbox

blkmapd: Fix infinite loop when reading serial

Message ID 556693B7.6040501@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kinglong Mee May 28, 2015, 4:04 a.m. UTC
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.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
---
 utils/blkmapd/device-inq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Kinglong Mee June 26, 2015, 11:12 p.m. UTC | #1
ping...

On 5/28/2015 12:04 PM, Kinglong Mee wrote:
> 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.
> 
> Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
> ---
>  utils/blkmapd/device-inq.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/blkmapd/device-inq.c b/utils/blkmapd/device-inq.c
> index c5bf71f..6b56b67 100644
> --- a/utils/blkmapd/device-inq.c
> +++ b/utils/blkmapd/device-inq.c
> @@ -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)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Steve Dickson June 30, 2015, 6:18 p.m. UTC | #2
On 05/28/2015 12:04 AM, Kinglong Mee wrote:
> 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.
> 
> Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Sorry for the delay.... Committed! 

steved.
> ---
>  utils/blkmapd/device-inq.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/blkmapd/device-inq.c b/utils/blkmapd/device-inq.c
> index c5bf71f..6b56b67 100644
> --- a/utils/blkmapd/device-inq.c
> +++ b/utils/blkmapd/device-inq.c
> @@ -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)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/utils/blkmapd/device-inq.c b/utils/blkmapd/device-inq.c
index c5bf71f..6b56b67 100644
--- a/utils/blkmapd/device-inq.c
+++ b/utils/blkmapd/device-inq.c
@@ -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)