From dev-return-13878-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Mon Mar 14 15:43:10 2005 Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 9217 invoked from network); 14 Mar 2005 15:43:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 14 Mar 2005 15:43:09 -0000 Received: (qmail 22365 invoked by uid 500); 14 Mar 2005 15:43:08 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 22324 invoked by uid 500); 14 Mar 2005 15:43:07 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 22311 invoked by uid 99); 14 Mar 2005 15:43:07 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of apr-dev@m.gmane.org designates 80.91.229.2 as permitted sender) Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 14 Mar 2005 07:43:06 -0800 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1DArZM-0007Hn-6s for dev@apr.apache.org; Mon, 14 Mar 2005 16:33:24 +0100 Received: from adsl-3-9-19.mia.bellsouth.net ([65.3.9.19]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 14 Mar 2005 16:33:24 +0100 Received: from joe+gmane by adsl-3-9-19.mia.bellsouth.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 14 Mar 2005 16:33:24 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: dev@apr.apache.org To: dev@apr.apache.org From: Joe Schaefer Subject: [PATCH] Fix apr_table_overlap when pools aren't the same Date: Mon, 14 Mar 2005 10:25:54 -0500 Lines: 70 Message-ID: <87ll8qs0zh.fsf@gemini.sunstarsys.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: adsl-3-9-19.mia.bellsouth.net Mail-Copies-To: never User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:H6e1AgGvaY0sCXPMu7e5GJos8Nc= Sender: news X-Gmane-MailScanner: Found to be clean X-Gmane-MailScanner: Found to be clean X-MailScanner-From: apr-dev@m.gmane.org X-MailScanner-To: dev@apr.apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Here's a semi-tested patch to fix apr_table_overlap when the pools differ. The current code wipes out the first argument's table when the pools differ, which is clearly inconsistent with the documented behavior (my fault probably, because I think this bug is due to an old patch of mine). I say "semi-tested" because the patch I wanted to submit would change all the POOL_DEBUG ifdefs in apr_tables.c to APR_POOL_DEBUG, but when I tested that against httpd's trunk there were lots of core files being generated. When I tried to write a patch for httpd, I noticed that apr_pool_join doesn't work (not implemented by apr), so at the moment I'm not sure if apr has abandoned the goal of being strict about pool ancenstry in the table ops. Anyways, here's the patch. I hope it helps. Index: tables/apr_tables.c =================================================================== --- tables/apr_tables.c (revision 157131) +++ tables/apr_tables.c (working copy) @@ -1190,16 +1190,20 @@ { const int m = a->a.nelts; const int n = b->a.nelts; - apr_pool_t *p = b->a.pool; if (m + n == 0) { return; } - /* copy (extend) a using b's pool */ - if (a->a.pool != p) { - make_array_core(&a->a, p, m+n, sizeof(apr_table_entry_t), 0); +#ifdef POOL_DEBUG + /* we don't copy keys and values, so it's necessary that b->a.pool + * have a life span at least as long as a->a.pool + */ + if (!apr_pool_is_ancestor(b->a.pool, a->a.pool)) { + fprintf(stderr, "overlap_table: b's pool is not an ancestor of a's\n"); + abort(); } +#endif apr_table_cat(a, b); Index: test/testtable.c =================================================================== --- test/testtable.c (revision 157131) +++ test/testtable.c (working copy) @@ -117,9 +117,14 @@ static void table_overlap(abts_case *tc, void *data) { const char *val; - apr_table_t *t1 = apr_table_make(p, 1); - apr_table_t *t2 = apr_table_make(p, 1); + apr_pool_t *subp; + apr_table_t *t1; + apr_table_t *t2; + apr_pool_create(&subp, p); + t1 = apr_table_make(subp, 1); + t2 = apr_table_make(p, 1); + apr_table_addn(t1, "a", "0"); apr_table_addn(t1, "g", "7"); apr_table_addn(t2, "a", "1"); -- Joe Schaefer