Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D36529157 for ; Wed, 20 Jun 2012 16:33:44 +0000 (UTC) Received: (qmail 78994 invoked by uid 500); 20 Jun 2012 16:33:44 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 78950 invoked by uid 500); 20 Jun 2012 16:33:44 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 78942 invoked by uid 99); 20 Jun 2012 16:33:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jun 2012 16:33:44 +0000 X-ASF-Spam-Status: No, hits=3.4 required=5.0 tests=FH_FAKE_RCVD_LINE_B,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ohaya@cox.net designates 68.230.241.213 as permitted sender) Received: from [68.230.241.213] (HELO eastrmfepo101.cox.net) (68.230.241.213) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jun 2012 16:33:37 +0000 Received: from eastrmimpo110.cox.net ([68.230.241.223]) by eastrmfepo101.cox.net (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP id <20120620163316.WHRS18243.eastrmfepo101.cox.net@eastrmimpo110.cox.net>; Wed, 20 Jun 2012 12:33:16 -0400 Received: from eastrmwml208 ([172.18.18.217]) by eastrmimpo110.cox.net with bizsmtp id QgZG1j0064h0NJL02gZGiE; Wed, 20 Jun 2012 12:33:16 -0400 X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020205.4FE1FB4C.0107,ss=1,re=0.000,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=1.1 cv=+gK3ZToMGMeqrPC4pxPliEYF7vrlQm/SKWBqsNRx23k= c=1 sm=1 a=7pXAvnUozvcA:10 a=G8Uczd0VNMoA:10 a=X0LLrcwhTTAA:10 a=IkcTkHD0fZMA:10 a=TRy/vagDvAN6zvr8h90PzQ==:17 a=kviXuzpPAAAA:8 a=F2nn6Ai_rqBeRy76i2sA:9 a=QEXdDO2ut3YA:10 a=4vB-4DCPJfMA:10 a=TRy/vagDvAN6zvr8h90PzQ==:117 X-CM-Score: 0.00 Authentication-Results: cox.net; none Received: from 72.192.248.102 by webmail.east.cox.net; Wed, 20 Jun 2012 12:33:16 -0400 Message-ID: <20120620123316.5Z3DI.162435.imail@eastrmwml208> Date: Wed, 20 Jun 2012 12:33:16 -0400 From: To: modules-dev@httpd.apache.org Subject: Re: Best (safest) way to edit char string (from envvars)? Cc: Daniel Gruno In-Reply-To: <4FE1F8C5.9020800@cord.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) Sensitivity: Normal X-Virus-Checked: Checked by ClamAV on apache.org ---- Daniel Gruno wrote: > On 06/20/2012 06:17 PM, ohaya@cox.net wrote: > > > > Hi Ben and Daniel, > > > > I must be doing wrong. After I added code to strip the begin and end lines, I get a segfault when I test. > > > > I notice that the apr_cpystrn() doesn't include a pool parameter, so I guess it's just moving the char strings in memory that already exists in the pool? > > > > Here's the code I have thus far: > > > > const char * ssl_client_cert; > > const char * ssl_client_cert_after_remove_begin; > > const char * ssl_client_cert_after_remove_end; > > int end_of_cert; > > > > printf("SSL_CLIENT_CERT=[%s]\n", apr_table_get(r->subprocess_env, "SSL_CLIENT_CERT")); > > ssl_client_cert = apr_table_get(r->subprocess_env, "SSL_CLIENT_CERT"); > > > > printf("printf ssl_client_cert=[%s]\n", ssl_client_cert); > > printf("ssl_client_cert + 27=[%s]\n", ssl_client_cert+27); > > > > // SEGFAULT after here... > > > > end_of_cert = strlen(ssl_client_cert); > > apr_cpystrn(ssl_client_cert_after_remove_begin, ssl_client_cert+27, end_of_cert-27 ); > > end_of_cert = strlen(ssl_client_cert); > > > > printf("printf ssl_client_cert_after_remove_begin=[%d]-[%s]\n", end_of_cert, ssl_client_cert_after_remove_begin); > > end_of_cert = strlen(ssl_client_cert_after_remove_begin); > > apr_cpystrn(ssl_client_cert_after_remove_end, ssl_client_cert_after_remove_begin+21, end_of_cert-21); > > > > printf("printf ssl_client_cert_after_remove_end=[%d]-[%s]\n", end_of_cert, ssl_client_cert_after_remove_end); > > > > Thanks, > > Jim > > > > > apr_cpystrn expects the destination to be already allocated space of the > correct size. > > You need to either allocate the space for your char* yourself via > apr_palloc or apr_pcalloc, or use apr_pstrndup instead, if you expect > httpd to handle the memory management. > > With regards, > Daniel. Hi, I'll try the palloc, but yourself and I think Ben mentioned apr_pstrndup(), and I don't quite understand that. It looks like pstrndup() just creates a new string in the pool that's the same size as the original string, but I don't quite understand why having that duplicated char string in the pool helps? Or, are you all suggesting using apr_pstrndup() to create a copy of string I want to manipulate, and then use something like: apr_cpystrn(newly_allocated_string, old_string+27, old_string_lgh-27) Thanks again! Jim