[Beowulf] Stupid MPI programming question
Jakob Oestergaard
jakob at unthought.net
Thu Sep 28 06:09:55 PDT 2006
On Thu, Sep 28, 2006 at 08:57:28AM -0400, Robert G. Brown wrote:
> On Thu, 28 Sep 2006, Jakob Oestergaard wrote:
...
> Ah, that's it. I'd forgotten this one and missed the write to a static
> string, although it has bitten me in the past (partly because back in
> the remote K&R past one could nearly always get away with it). This is
> also a way that buffer overwrite attacks can begin if any nefarious
> human can control the string that is overwritten IIRC...
>
> Although in this particular case, that should have produced a very
> different error than -1 on the mkdir call, should it not?
Well, if the write doesn't give him a segfault and he's allowed to write
to memory that shouldn't be written to, then I guess pretty much
anything can happen after that.
> And he was
> writing out the results string per node right before calling as well, so
> his compiler was probably letting him get away with it or failing in
> some odd way later.
Yup
I wonder if valgrind would have caught it...
>
> >What you probably want to do is:
> >---
> >char foo[1024]; // 1KiB on the stack - writable
> >strncpy(foo, sizeof foo, "my test"); // Assign contents by copying
> >...
> >foo[0] = ' '; // <- fine
> >---
>
> Absolutely.
Uh, except I meant strncpy(foo, "my test", sizeof foo) of course...
Cheers,
--
/ jakob
More information about the Beowulf
mailing list