httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <oh...@cox.net>
Subject Re: Best (safest) way to edit char string (from envvars)?
Date Wed, 20 Jun 2012 15:21:05 GMT

---- Ben Noordhuis <info@bnoordhuis.nl> wrote: 
> On Wed, Jun 20, 2012 at 4:35 PM,  <ohaya@cox.net> 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.

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 string.

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

Mime
View raw message