]> xenbits.xensource.com Git - xen.git/commitdiff
tools/blktap2: fix out of bounds access in block-log.c
authorOlaf Hering <olaf@aepfle.de>
Thu, 10 May 2012 10:20:04 +0000 (11:20 +0100)
committerOlaf Hering <olaf@aepfle.de>
Thu, 10 May 2012 10:20:04 +0000 (11:20 +0100)
block-log.c: In function 'ctl_close_sock':
block-log.c:363:23: warning: array subscript is above array bounds
[-Warray-bounds]

Adjust loop condition in ctl_close_sock() to fix warning.
Adjust array acccess in ctl_close() to actually access the array
member.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Keir Fraser <keir@xen.org>
tools/blktap2/drivers/block-log.c

index 6a63729eca2e334bf681a11023e301d8f9852335..5330cdc4363937ffab96e5879c8162d2d51b68fc 100644 (file)
@@ -324,11 +324,11 @@ static int ctl_open(struct tdlog_state* s, const char* name)
 static int ctl_close(struct tdlog_state* s)
 {
   while (s->connected) {
+    s->connected--;
     tapdisk_server_unregister_event(s->connections[s->connected].id);
     close(s->connections[s->connected].fd);
     s->connections[s->connected].fd = -1;
     s->connections[s->connected].id = 0;
-    s->connected--;
   }
 
   if (s->ctl.fd >= 0) {
@@ -359,7 +359,7 @@ static int ctl_close_sock(struct tdlog_state* s, int fd)
 {
   int i;
 
-  for (i = 0; i <= s->connected; i++) {
+  for (i = 0; i < s->connected; i++) {
     if (s->connections[i].fd == fd) {
       tapdisk_server_unregister_event(s->connections[i].id);
       close(s->connections[i].fd);