httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Noordhuis <>
Subject Re: Best (safest) way to edit char string (from envvars)?
Date Wed, 20 Jun 2012 14:42:11 GMT
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 like:
> 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.

View raw message