Re: colortail crash and fix
Robert Nagy wrote: > Hey, > > Can you guys try this diff? oh, fun, upstream fixed it a different way. i don't have a full ports tree on this laptop, but the new code looks like it could work. // set filename in options class string str = filename.str(); char* cs = new char[str.length()+1]; std::strcpy(cs, str.c_str()); o->cfg_filenames[o->nr_cfg_files] = cs; // set filename in options class string str = filename.str(); char* cs = new char[str.length()+1]; std::strcpy(cs, str.c_str()); o->cfg_filenames[o->nr_cfg_files] = cs;
Re: colortail crash and fix
Hey, Can you guys try this diff? http://ix.io/286T On 22/01/20 20:35 -0500, Ted Unangst wrote: > Today's selected c++ reading: > Before any call to str() that uses the result as a C string, > the buffer must be null-terminated, typically with std::ends. > > Found by mlarkin using MALLOC_OPTIONS=SU. > > I leave it to the ports wizards to incorporate the patch. > > > --- OptionsParser.cc.orig Wed Aug 4 19:23:39 1999 > +++ OptionsParser.cc Wed Jan 22 20:32:29 2020 > @@ -17,8 +17,8 @@ > Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > */ > > -#include > -#include > +#include > +#include > #include > #include > #include > @@ -27,6 +27,8 @@ > #include "Info.h" > #include "Usage.h" > > +using namespace std; > + > // methods for class Options > > Options::Options() > @@ -138,6 +140,7 @@ > { >// found seperator >// set filename in options class > + filename << std::ends; >o->cfg_filenames[o->nr_cfg_files] = filename.str(); > >// increase the nr_cfg_files counter > @@ -154,6 +157,7 @@ > { >// found end of string >// set filename in options class > + filename << std::ends; >o->cfg_filenames[o->nr_cfg_files] = filename.str(); > >// increase the nr_cfg_files counter > -- Regards, Robert Nagy
colortail crash and fix
Today's selected c++ reading: Before any call to str() that uses the result as a C string, the buffer must be null-terminated, typically with std::ends. Found by mlarkin using MALLOC_OPTIONS=SU. I leave it to the ports wizards to incorporate the patch. --- OptionsParser.cc.orig Wed Aug 4 19:23:39 1999 +++ OptionsParser.ccWed Jan 22 20:32:29 2020 @@ -17,8 +17,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include +#include +#include #include #include #include @@ -27,6 +27,8 @@ #include "Info.h" #include "Usage.h" +using namespace std; + // methods for class Options Options::Options() @@ -138,6 +140,7 @@ { // found seperator // set filename in options class +filename << std::ends; o->cfg_filenames[o->nr_cfg_files] = filename.str(); // increase the nr_cfg_files counter @@ -154,6 +157,7 @@ { // found end of string // set filename in options class +filename << std::ends; o->cfg_filenames[o->nr_cfg_files] = filename.str(); // increase the nr_cfg_files counter