Boost logo

Boost Users :

Subject: Re: [Boost-users] [Filesystem] String corruption in path in V3 and Boost 1.44
From: Will Watts (willw_at_[hidden])
Date: 2010-09-23 05:08:31


In article <i7dpnt$rqv$1_at_[hidden]>, Timothy Madden wrote:
> I think that somehow the template constructor for paths takes the
> entire array passed as argument and not just the null-terminated
> string inside the array, which may be smaller.

This seems to be bang on, as does Scott's speculation as to how it came
about. I made a variation of my original experiment, which demonstrates
it:

  const char * f = "foo";
  const char * g = "bar";

  char b[10];
  strcpy(b, f);
  strcpy(b + strlen(f) + 1, g);
  // b contains 'f','o','o',0,'b','a','r', 0, Garbage, Garbage
  fs::path p1(b); // p1.m_pathname.size = 9
  fs::path p2(f); // p1.m_pathname.size = 3
  // prints "foo bar?" where ? is 8-bit garbage character
  cout << p1 << endl;
  // prints "foo"
  cout << p2 << endl;
  cout << (p1 == p2) << endl; // prints 1
  
The last line proves that in some circumstances the nul byte is
ignored, in others it is treated as significant.

I am surprised the path class can 'know' the length of a C array. I
guess that's the magic of templates for me.

> I also got a crash with the attached code on Visual Studio 2008.
> I have created a track ticket
> https://svn.boost.org/trac/boost/ticket/4677, lets hope someone picks
> it up.

Top work!

Will


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net