octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SIGABRT when testing md5sum.cc


From: John W. Eaton
Subject: Re: SIGABRT when testing md5sum.cc
Date: Tue, 23 Nov 2010 02:25:52 -0500

On 22-Nov-2010, jkirby wrote:

| I saw this crash on a msvc build. null-termination of sprintf not being
| accounted for? 
| 
| 
| diff -r 521f2bb7c443 liboctave/oct-md5.cc
| --- a/liboctave/oct-md5.cc    Thu Nov 18 20:14:52 2010 -0500
| +++ b/liboctave/oct-md5.cc    Mon Nov 22 22:36:54 2010 -0500
| @@ -36,7 +36,7 @@
|  static std::string
|  oct_md5_result_to_str (const unsigned char *buf)
|  {
| -  char tmp [32];
| +     char tmp [32+1] = { 0 };
|  
|    for (octave_idx_type i = 0; i < 16; i++)
|      sprintf (&tmp[2*i], "%02x", buf[i]);

I don't understand how that can matter.  The complete function is

  static std::string
  oct_md5_result_to_str (const unsigned char *buf)
  {
    char tmp [32];

    for (octave_idx_type i = 0; i < 16; i++)
      sprintf (&tmp[2*i], "%02x", buf[i]);

    return std::string (tmp, 32);
  }

and since the std::string constructor includes the length of the array
pointed to by tmp, it should not be going past the first 32 characters
of the array.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]