From patchwork Thu Dec 28 22:52:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 164 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director3.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id 7Q97AEgxTloTJQAAgoeIoA for ; Thu, 04 Jan 2018 08:51:04 -0500 Received: from proxy9.mail.ord1d.rsapps.net ([172.30.191.6]) by director3.mail.ord1d.rsapps.net (Dovecot) with LMTP id u7P7EEgxTlosQQAAkXNnRw ; Thu, 04 Jan 2018 08:51:04 -0500 Received: from smtp10.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy9.mail.ord1d.rsapps.net (Dovecot) with LMTP id oStUDUgxTlrDYQAA7h+8OQ ; Thu, 04 Jan 2018 08:51:04 -0500 X-Spam-Exception: WHITELISTED X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: patchwork@openvpn.net X-Originating-Ip: [184.106.54.93] Authentication-Results: smtp10.gate.ord1d.rsapps.net; iprev=pass policy.iprev="184.106.54.93"; spf=pass smtp.mailfrom="samuli@openvpn.net" smtp.helo="smtp93.ord1d.emailsrvr.com"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=fox-it.com X-Classification-ID: 4e2edaea-f156-11e7-b6a4-52540013bccb-1-1 Received: from [184.106.54.93] ([184.106.54.93:32809] helo=smtp93.ord1d.emailsrvr.com) by smtp10.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 22/4A-25340-7413E4A5; Thu, 04 Jan 2018 08:51:03 -0500 Received: from smtp20.relay.ord1d.emailsrvr.com (localhost [127.0.0.1]) by smtp20.relay.ord1d.emailsrvr.com (SMTP Server) with ESMTP id E0BA1C0080 for ; Thu, 4 Jan 2018 08:51:03 -0500 (EST) X-Auth-ID: samuli@openvpn.net Received: by smtp20.relay.ord1d.emailsrvr.com (Authenticated sender: samuli-AT-openvpn.net) with ESMTPSA id 60DBFC006B for ; Thu, 4 Jan 2018 08:51:03 -0500 (EST) X-Sender-Id: samuli@openvpn.net Received: from [192.168.15.45] (91-159-32-223.elisa-laajakaista.fi [91.159.32.223]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:465 (trex/5.7.12); Thu, 04 Jan 2018 08:51:03 -0500 Resent-From: =?utf-8?q?Samuli_Sepp=C3=A4nen?= Resent-To: patchwork@openvpn.net Resent-Date: Thu, 4 Jan 2018 15:51:01 +0200 Resent-Message-ID: Resent-User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 Received: from MBX10D-ORD1.mex06.mlsrvr.com (172.29.1.29) by MBX10C-ORD1.mex06.mlsrvr.com (172.29.1.28) with Microsoft SMTP Server (TLS) id 15.0.1293.2 via Mailbox Transport; Fri, 29 Dec 2017 03:53:19 -0600 Received: from MBX09D-ORD1.mex06.mlsrvr.com (172.29.1.26) by MBX10D-ORD1.mex06.mlsrvr.com (172.29.1.29) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Fri, 29 Dec 2017 03:53:19 -0600 Received: from gate.forward.smtp.iad3a.emailsrvr.com (204.232.172.40) by MBX09D-ORD1.mex06.mlsrvr.com (172.29.1.26) with Microsoft SMTP Server (TLS) id 15.0.1293.2 via Frontend Transport; Fri, 29 Dec 2017 03:53:19 -0600 Received: from [216.34.181.88] ([216.34.181.88:50772] helo=lists.sourceforge.net) by smtp18.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 9F/C1-05255-F80164A5; Fri, 29 Dec 2017 04:53:19 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eUrLI-0000hG-9t; Fri, 29 Dec 2017 09:52:44 +0000 Received: from sfi-mx-2.v28.ch3.sourceforge.com ([172.29.28.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eUrLG-0000gy-Up for openvpn-devel@lists.sourceforge.net; Fri, 29 Dec 2017 09:52:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wc0sjAJ+hRvIpCB2V3qpt48p57JHGleO5AhrKR5O8u4=; b=YPZCct6fK3rykElqtWavwPSWPy 1zhdMqmbakdE2T0s6Z67XqzyUew4xx81s0UvsaPqesn6Bf8chUAnmooAYVdLIQ91SxYBDJq6ifvJS hWFCFpXOuuhrKTgpIV3XK6m4ebqTJaP779NkTrINbsgHchh0DUmdlrDRqNObxLwuv/RU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wc0sjAJ+hRvIpCB2V3qpt48p57JHGleO5AhrKR5O8u4=; b=gZ/D37Ge6birhEyZ3Yu4Ffp1co 0GWeGNYljalknAzcwO2mzSVcSIkXb0ux602xNhvnVkKe94P2qNbdXBxXJdwk4lpSRaXMJx0ceuhUZ wERaFNd7JyyEHb3oSdEvHg8867y7KElv49ZvtbjfR7IpKzO56xthyCQZIRj9JF3rhasc=; Received: from ns2.fox-it.com ([178.250.144.131]) by sfi-mx-2.v28.ch3.sourceforge.com with esmtps (TLSv1:ECDHE-RSA-AES256-SHA:256) (Exim 4.89) id 1eUrLF-0003CV-QE for openvpn-devel@lists.sourceforge.net; Fri, 29 Dec 2017 09:52:42 +0000 Received: from FOXDFT52.FOX.local (unknown [10.0.0.129]) by ns2.fox-it.com (Postfix) with ESMTPS id E26001AF767 for ; Fri, 29 Dec 2017 10:52:35 +0100 (CET) Received: from steffan-fox.fox.local (10.0.3.167) by FOXDFT52.FOX.local (10.0.0.129) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Fri, 29 Dec 2017 10:52:35 +0100 From: Steffan Karger To: Date: Fri, 29 Dec 2017 10:52:24 +0100 Message-ID: <1514541144-19407-1-git-send-email-steffan.karger@fox-it.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-ClientProxiedBy: FOXDFT52.FOX.local (10.0.0.129) To FOXDFT52.FOX.local (10.0.0.129) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1eUrLF-0003CV-QE Subject: [Openvpn-devel] [PATCH 2/5 v3] buffer_list_aggregate_separator(): update list size after aggregating X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-MS-Exchange-Organization-Network-Message-Id: 720ffa4e-7bfa-48f8-4095-08d54ea1fd99 X-MS-Exchange-Organization-AVStamp-Mailbox: SMEXzs^g;1387100;0;This mail has been scanned by Trend Micro ScanMail for Microsoft Exchange; X-MS-Exchange-Organization-AuthSource: MBX09D-ORD1.mex06.mlsrvr.com X-MS-Exchange-Organization-AuthAs: Anonymous MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: Inbox After aggregating a buffer_list, the size should be adjusted accordingly. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v2: rebase on master v3: add spaces around '-' src/openvpn/buffer.c | 1 + tests/unit_tests/openvpn/test_buffer.c | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index e601a31..28ce8ca 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -1257,6 +1257,7 @@ buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const e = next; } bl->head = f; + bl->size -= count - 1; f->next = more; if (!more) { diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index b4625bb..bddb30a 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -138,8 +138,7 @@ test_buffer_list_aggregate_separator_two(void **state) /* Aggregate the first two elements */ /* FIXME this exceeds the supplied max */ buffer_list_aggregate_separator(ctx->one_two_three, 4, testsep); - /* FIXME size does not get adjusted after aggregating */ - assert_int_equal(ctx->one_two_three->size, 3); + assert_int_equal(ctx->one_two_three->size, 2); struct buffer *buf = buffer_list_peek(ctx->one_two_three); assert_buf_equals_str(buf, teststr1 testsep teststr2 testsep); } @@ -151,8 +150,7 @@ test_buffer_list_aggregate_separator_all(void **state) /* Aggregate all */ buffer_list_aggregate_separator(ctx->one_two_three, 1<<16, testsep); - /* FIXME size does not get adjusted after aggregating */ - assert_int_equal(ctx->one_two_three->size, 3); + assert_int_equal(ctx->one_two_three->size, 1); struct buffer *buf = buffer_list_peek(ctx->one_two_three); assert_buf_equals_str(buf, teststr1 testsep teststr2 testsep teststr3 testsep); @@ -165,8 +163,7 @@ test_buffer_list_aggregate_separator_nosep(void **state) /* Aggregate all */ buffer_list_aggregate_separator(ctx->one_two_three, 1<<16, testnosep); - /* FIXME size does not get adjusted after aggregating */ - assert_int_equal(ctx->one_two_three->size, 3); + assert_int_equal(ctx->one_two_three->size, 1); struct buffer *buf = buffer_list_peek(ctx->one_two_three); assert_buf_equals_str(buf, teststr1 teststr2 teststr3); } @@ -179,8 +176,7 @@ test_buffer_list_aggregate_separator_zerolen(void **state) /* Aggregate all */ buffer_list_aggregate_separator(bl_zerolen, 1<<16, testnosep); - /* FIXME size does not get adjusted after aggregating */ - assert_int_equal(bl_zerolen->size, 2); + assert_int_equal(bl_zerolen->size, 1); struct buffer *buf = buffer_list_peek(bl_zerolen); assert_buf_equals_str(buf, ""); } @@ -193,8 +189,7 @@ test_buffer_list_aggregate_separator_emptybuffers(void **state) /* Aggregate all */ buffer_list_aggregate_separator(bl_emptybuffers, 1<<16, testnosep); - /* FIXME size does not get adjusted after aggregating */ - assert_int_equal(bl_emptybuffers->size, 2); + assert_int_equal(bl_emptybuffers->size, 1); struct buffer *buf = buffer_list_peek(bl_emptybuffers); assert_int_equal(BLEN(buf), 0); } From patchwork Thu Dec 28 22:53:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 163 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director5.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id AzWaEj8xTlosbwAAgoeIoA for ; Thu, 04 Jan 2018 08:50:55 -0500 Received: from proxy12.mail.ord1d.rsapps.net ([172.30.191.6]) by director5.mail.ord1d.rsapps.net (Dovecot) with LMTP id K7KLEj8xTlqPAgAAsdCWiw ; Thu, 04 Jan 2018 08:50:55 -0500 Received: from smtp4.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.ord1d.rsapps.net (Dovecot) with LMTP id UgSfET8xTlopTQAA7PHxkg ; Thu, 04 Jan 2018 08:50:55 -0500 X-Spam-Exception: WHITELISTED X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: patchwork@openvpn.net X-Originating-Ip: [184.106.54.69] Authentication-Results: smtp4.gate.ord1d.rsapps.net; iprev=pass policy.iprev="184.106.54.69"; spf=pass smtp.mailfrom="samuli@openvpn.net" smtp.helo="smtp69.ord1d.emailsrvr.com"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=fox-it.com X-Classification-ID: 48f6e46e-f156-11e7-92b1-525400760ffc-1-1 Received: from [184.106.54.69] ([184.106.54.69:55442] helo=smtp69.ord1d.emailsrvr.com) by smtp4.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id A8/67-11499-F313E4A5; Thu, 04 Jan 2018 08:50:55 -0500 Received: from smtp1.relay.ord1d.emailsrvr.com (localhost [127.0.0.1]) by smtp1.relay.ord1d.emailsrvr.com (SMTP Server) with ESMTP id 2930E40088 for ; Thu, 4 Jan 2018 08:50:55 -0500 (EST) X-Auth-ID: samuli@openvpn.net Received: by smtp1.relay.ord1d.emailsrvr.com (Authenticated sender: samuli-AT-openvpn.net) with ESMTPSA id 9C8524006D for ; Thu, 4 Jan 2018 08:50:54 -0500 (EST) X-Sender-Id: samuli@openvpn.net Received: from [192.168.15.45] (91-159-32-223.elisa-laajakaista.fi [91.159.32.223]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:465 (trex/5.7.12); Thu, 04 Jan 2018 08:50:55 -0500 Resent-From: =?utf-8?q?Samuli_Sepp=C3=A4nen?= Resent-To: patchwork@openvpn.net Resent-Date: Thu, 4 Jan 2018 15:50:53 +0200 Resent-Message-ID: <6623cc20-5483-5cd9-7b52-858e284b54ad@openvpn.net> Resent-User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 Received: from MBX10D-ORD1.mex06.mlsrvr.com (172.29.1.29) by MBX10C-ORD1.mex06.mlsrvr.com (172.29.1.28) with Microsoft SMTP Server (TLS) id 15.0.1293.2 via Mailbox Transport; Fri, 29 Dec 2017 03:54:13 -0600 Received: from MBX10C-ORD1.mex06.mlsrvr.com (172.29.1.28) by MBX10D-ORD1.mex06.mlsrvr.com (172.29.1.29) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Fri, 29 Dec 2017 03:54:12 -0600 Received: from gate.forward.smtp.iad3a.emailsrvr.com (204.232.172.40) by MBX10C-ORD1.mex06.mlsrvr.com (172.29.1.28) with Microsoft SMTP Server (TLS) id 15.0.1293.2 via Frontend Transport; Fri, 29 Dec 2017 03:54:12 -0600 Received: from [216.34.181.88] ([216.34.181.88:51120] helo=lists.sourceforge.net) by smtp38.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 0E/45-10374-4C0164A5; Fri, 29 Dec 2017 04:54:12 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eUrM2-0000r8-Jk; Fri, 29 Dec 2017 09:53:30 +0000 Received: from sfi-mx-1.v28.ch3.sourceforge.com ([172.29.28.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eUrM0-0000qf-Jp for openvpn-devel@lists.sourceforge.net; Fri, 29 Dec 2017 09:53:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=h8S0POSZOhA7b+HJkWLS5PV1qjPrZosQhWzYfiqsj08=; b=kQQ1ykzVdRzjf8ncxMmxIHaLTV Mm+KjxuxJ4ieiyExYyeDMBX+WdcYcIExmHCeu8CPV/kwV2uaumC5jfzdy7PJQcVzvcIcemPIH/F10 4lRWDYjSiXXP6arWBSBf4uCDFzQcixlZBvrdUP4Nux/y7lmxA219uXh7C7ITtazPe6Rc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=h8S0POSZOhA7b+HJkWLS5PV1qjPrZosQhWzYfiqsj08=; b=DZjZkmY6NiA2H1WA3rI+XSgO/L MSQh7uvMOS2IvYSCvRk8Z0mvq4GJQ7Q6OD9I/WrPIpUDfmqPJ+9/hN6ut41PffmXaNw0dF3rZD9Oy ecE/da5SY1pe/TcuMUFwKt86Ev2ELAW2mnpejHpmTEMYjOtARaCvZ00HftQkNxRgJWzc=; Received: from ns2.fox-it.com ([178.250.144.131]) by sfi-mx-1.v28.ch3.sourceforge.com with esmtps (TLSv1:ECDHE-RSA-AES256-SHA:256) (Exim 4.89) id 1eUrLz-0008Qi-II for openvpn-devel@lists.sourceforge.net; Fri, 29 Dec 2017 09:53:28 +0000 Received: from FOXDFT52.FOX.local (unknown [10.0.0.129]) by ns2.fox-it.com (Postfix) with ESMTPS id 936191AF767 for ; Fri, 29 Dec 2017 10:53:21 +0100 (CET) Received: from steffan-fox.fox.local (10.0.3.167) by FOXDFT52.FOX.local (10.0.0.129) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Fri, 29 Dec 2017 10:53:21 +0100 From: Steffan Karger To: Date: Fri, 29 Dec 2017 10:53:11 +0100 Message-ID: <1514541191-19471-1-git-send-email-steffan.karger@fox-it.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-ClientProxiedBy: FOXDFT52.FOX.local (10.0.0.129) To FOXDFT52.FOX.local (10.0.0.129) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1eUrLz-0008Qi-II Subject: [Openvpn-devel] [PATCH 3/5 v3] buffer_list_aggregate_separator(): don't exceed max_len X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-MS-Exchange-Organization-Network-Message-Id: 30309b13-e700-40f9-0c89-08d54ea21d5a X-MS-Exchange-Organization-AVStamp-Mailbox: SMEXzs^g;1387100;0;This mail has been scanned by Trend Micro ScanMail for Microsoft Exchange; X-MS-Exchange-Organization-AuthSource: MBX10C-ORD1.mex06.mlsrvr.com X-MS-Exchange-Organization-AuthAs: Anonymous MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: Inbox buffer_list_aggregate_separator() would merge buffer_list entries until it had exceeded the provided max_len, instead of stopping *before* exceeding the max value. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v2: rebase on 1/5 v2 (other patches should still apply) v3: as suggested by ordex, reorder if contitions and add spaces around '+' src/openvpn/buffer.c | 13 ++++++++++--- src/openvpn/buffer.h | 3 ++- tests/unit_tests/openvpn/test_buffer.c | 11 +++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 28ce8ca..2656702 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -1223,7 +1223,8 @@ buffer_list_peek(struct buffer_list *ol) } void -buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const char *sep) +buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max_len, + const char *sep) { int sep_len = strlen(sep); @@ -1232,9 +1233,15 @@ buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const struct buffer_entry *more = bl->head; size_t size = 0; int count = 0; - for (count = 0; more && size <= max; ++count) + for (count = 0; more; ++count) { - size += BLEN(&more->buf) + sep_len; + size_t extra_len = BLEN(&more->buf) + sep_len; + if (size + extra_len > max_len) + { + break; + } + + size += extra_len; more = more->next; } diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index b73f6c8..e588b80 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -1107,7 +1107,8 @@ void buffer_list_pop(struct buffer_list *ol); void buffer_list_aggregate(struct buffer_list *bl, const size_t max); -void buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const char *sep); +void buffer_list_aggregate_separator(struct buffer_list *bl, + const size_t max_len, const char *sep); struct buffer_list *buffer_list_file(const char *fn, int max_line_len); diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index bddb30a..5af9332 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -134,13 +134,16 @@ static void test_buffer_list_aggregate_separator_two(void **state) { struct test_buffer_list_aggregate_ctx *ctx = *state; + const char *expected = teststr1 testsep teststr2 testsep; - /* Aggregate the first two elements */ - /* FIXME this exceeds the supplied max */ - buffer_list_aggregate_separator(ctx->one_two_three, 4, testsep); + /* Aggregate the first two elements + * (add 1 to max_len to test if "three" is not sneaked in too) + */ + buffer_list_aggregate_separator(ctx->one_two_three, strlen(expected) + 1, + testsep); assert_int_equal(ctx->one_two_three->size, 2); struct buffer *buf = buffer_list_peek(ctx->one_two_three); - assert_buf_equals_str(buf, teststr1 testsep teststr2 testsep); + assert_buf_equals_str(buf, expected); } static void