Re: test/heartbleed_test.c

2014-05-20 Thread Ben Laurie
On 20 May 2014 06:40, The Doctor,3328-138 Ave Edmonton AB T5Y
1M4,669-2000,473-4587 doc...@doctor.nl2k.ab.ca wrote:
 Found that strndup would not work.

 I had to add

 #if !HAVE_STRNDUP

 #include stdio.h
 #include string.h
 #include sys/types.h
 #include malloc.h

 /* Find the length of STRING, but scan at most MAXLEN characters.
If no '\0' terminator is found in that many characters, return MAXLEN.  */
 size_t
 strnlen (const char *string, size_t maxlen)
 {
   const char *end = memchr (string, '\0', maxlen);
   return end ? end - string : maxlen;
 }

 char *
 strndup (const char *s, size_t n)
 {
   size_t len = strnlen (s, n);
   char *new = malloc (len + 1);

   if (new == NULL)
 return NULL;

   new[len] = '\0';
   return memcpy (new, s, len);
 }

 #endif

 Please see how you can add this.

There is already a strndup replacement: BUF_strndup(). Switching to
use that would be better.
__
OpenSSL Project http://www.openssl.org
Development Mailing List   openssl-dev@openssl.org
Automated List Manager   majord...@openssl.org


Re: test/heartbleed_test.c

2014-05-20 Thread Ken Goldman

On 5/20/2014 7:24 AM, Ben Laurie wrote:


There is already a strndup replacement: BUF_strndup(). Switching to
use that would be better.


However

- if that function points to strndup, don't you still have the problem 
if strndup doesn't exist?


- if that function is a reimplementation of strndup, don't you lose any 
optimizations that the tool chain strndup might have made?



__
OpenSSL Project http://www.openssl.org
Development Mailing List   openssl-dev@openssl.org
Automated List Manager   majord...@openssl.org