Received: from eggs.gnu.org ([2001:4830:134:3::10]:50495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqKCG-0002Er-5Z for qemu-devel@nongnu.org; Sat, 22 Jun 2013 05:33:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UqKCF-0007tD-2d for qemu-devel@nongnu.org; Sat, 22 Jun 2013 05:33:27 -0400 From: Michael Tokarev Date: Sat, 22 Jun 2013 13:24:28 +0400 Message-Id: <1371893076-9643-10-git-send-email-mjt@msgid.tls.msk.ru> In-Reply-To: <1371893076-9643-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1371893076-9643-1-git-send-email-mjt@msgid.tls.msk.ru> Subject: [Qemu-devel] [PULL 09/17] acl: acl_add can't insert before last list element, fix List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-stable@nongnu.org, Michael Tokarev , Markus Armbruster , qemu-devel@nongnu.org From: Markus Armbruster Watch this: $ upstream-qemu -nodefaults -S -vnc :0,acl,sasl -monitor stdio QEMU 1.5.50 monitor - type 'help' for more information (qemu) acl_add vnc.username drei allow acl: added rule at position 1 (qemu) acl_show vnc.username policy: deny 1: allow drei (qemu) acl_add vnc.username zwei allow 1 acl: added rule at position 2 (qemu) acl_show vnc.username policy: deny 1: allow drei 2: allow zwei (qemu) acl_add vnc.username eins allow 1 acl: added rule at position 1 (qemu) acl_show vnc.username policy: deny 1: allow eins 2: allow drei 3: allow zwei The second acl_add inserts at position 2 instead of 1. Root cause is an off-by-one in qemu_acl_insert(): when index == acl->nentries, it appends instead of inserting before the last list element. Cc: qemu-stable@nongnu.org Signed-off-by: Markus Armbruster Reviewed-by: Michael Roth Signed-off-by: Michael Tokarev --- util/acl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/acl.c b/util/acl.c index a7f33ff..938b7ae 100644 --- a/util/acl.c +++ b/util/acl.c @@ -138,9 +138,9 @@ int qemu_acl_insert(qemu_acl *acl, if (index <= 0) return -1; - if (index >= acl->nentries) + if (index > acl->nentries) { return qemu_acl_append(acl, deny, match); - + } entry = g_malloc(sizeof(*entry)); entry->match = g_strdup(match); -- 1.7.10.4