Re: opendir - Unix

This is a discussion on Re: opendir - Unix ; On Tue, 08 Jul 2008 12:25:42 -0500, MK wrote: > I don't use c much but I've done lots of perl, perl/Tk, and shellcode on > LINUX. > > I'm trying to do things with directory trees and i occasionally ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Re: opendir

  1. Re: opendir

    On Tue, 08 Jul 2008 12:25:42 -0500, MK wrote:

    > I don't use c much but I've done lots of perl, perl/Tk, and shellcode on
    > LINUX.
    >
    > I'm trying to do things with directory trees and i occasionally get back
    > an errno from opendir "No such file or directory" while my program is
    > working its way thru a tree. This always happens with the same
    > directory (ie. it is not totally random) although there is nothing
    > different or unusual about the ownership or permissions (ie. there
    > actually is such a readable directory).


    > strcpy(invalid, ".");
    > strcat(invalid, ".");


    Are you entering the IOCCC? That has got to be the world's most
    around-the-houses way to get ".." I have ever seen! What is wrong with
    strcmp( foo, ".." ) like that?

    Also, you declared:
    > char invalid[2],


    So you have overflowed the fixed length buffer right there (".." requires
    _three_ bytes).

    More likely to be the cause of the problem is:
    > stat(fullname,&dstuff);


    You must check the return value of stat(). It may tell when something is
    wrong.

    Perhaps trying lstat() may reveal something, too. I'm thinking in
    particular of a dangling symlink.

    Cross-posted and followup-to comp.unix.programmer. I'm not saying you
    can or can't use c.l.c for this (and am not really bothered what the
    various playground gangs have to say on the subject), but you will
    probably get better help there on this problem.

    HTH
    viza

  2. Re: opendir

    On Tue, 08 Jul 2008 18:39:24 +0000, viza wrote:

    > On Tue, 08 Jul 2008 12:25:42 -0500, MK wrote:
    >
    >> I don't use c much but I've done lots of perl, perl/Tk, and shellcode
    >> on LINUX.


    >
    >> strcpy(invalid, ".");
    >> strcat(invalid, ".");

    >
    > Are you entering the IOCCC? That has got to be the world's most
    > around-the-houses way to get ".." I have ever seen! What is wrong with
    > strcmp( foo, ".." ) like that?


    yes, that's kind of an interesting product of myopathy and "is this more
    or less awkward than perl, so..." anyway, i took out retv and invalid.
    thanks!

    >
    > Also, you declared:
    >> char invalid[2],

    >
    > So you have overflowed the fixed length buffer right there (".."
    > requires _three_ bytes).


    yep, get that \0; however it was not an overflow that caused the
    problem...


    > More likely to be the cause of the problem is:
    >> stat(fullname,&dstuff);

    >
    > You must check the return value of stat(). It may tell when something
    > is wrong.


    will do, added "if (stat(fullname,&dstuff) != 0) {error..." (that wasn't
    it either tho)

    > Perhaps trying lstat() may reveal something, too. I'm thinking in
    > particular of a dangling symlink.


    this happens in trees with no symlinks in them.

    > Cross-posted and followup-to comp.unix.programmer.


    okay, will try -- thanx again. much.

+ Reply to Thread