httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Gruno <>
Subject Re: Best (safest) way to edit char string (from envvars)?
Date Wed, 20 Jun 2012 15:24:29 GMT
On 06/20/2012 05:21 PM, wrote:
> ---- Ben Noordhuis <> wrote: 
>> On Wed, Jun 20, 2012 at 4:35 PM,  <> wrote:
>>> Hi,
>>> I am working on a module, and I get one of the SSL envvars, SSL_CLIENT_CERT,
using apr_table_get() into a const char *.
>>> The client cert char string returned has the extra beginning line (-----BEGIN
CERTIFICATE-----) and ending line (-----END CERTIFICATE-----), but I need to remove both of
those lines for a call that I need to make.
>>> I have to admit, I'm a bit (a lot) rusty with 'C', and I guess I could do something
>>> strpy(original_cert, original_cert+27);
>>> and then set the ending position to \0 (to terminate the char string early),
but since with this is a module, and I'm working with a pointer to the memory pool, I'm kind
of worried that doing stuff like that would mess things up (e.g., garbage collection, since
the string is now shorter by 'x' bytes.
>>> So, from an Apache module development standpoint, what would be the safest way
to do this (strip a string of chars from the beginning and end)?
>> Make a copy with apr_strdup(), then mutate the copy.
>> APR has utility functions for manipulating strings, like apr_strtok().
>> Have a look at apr_strings.h.
> Hi,
> Thanks.  I've been using those, and I can eliminate the beginning line, but how can I
eliminate the ending line?  It seems that I can't just store a '\0' into the end of the char
> Will apr_cpystrn() automatically terminate the destination char string, i.e., if I do
something like:
> apr_cpystrn(cert_without_ending, cert_string, strlen(cert_string)-10);
> will the cert_without_ending char string get terminated properly with \0?
> Jim
Yes, apr_cpystrn includes a terminating null char, as mentioned in the

With regards,

View raw message