[AD] Possible bug in src/libc.c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


While answering question about findfirst()/findnext() emulation, I took a
look on POSIX emulation of these functions and saw this in src/libc.c:279.

      if ((ff_info->stat.st_mode & S_IRUSR) == 0)
         ffblk->ff_attrib |= FA_RDONLY;

S_IRUSR means that user has read permissions - should not it been changed
to S_IWUSR? Of course, this test is also wrong, because it tests only
presence of write permission for owner of that file, not user executing
Allegro program. It should be changed to something more complicated like:

if ((ff_info->stat.st_uid == geteuid())
    && ((ff_info->stat.st_mode & S_IWUSR) == 0))
         ffblk->ff_attrib |= FA_RDONLY;
else if ((ff_info->stat.st_gid == getegid())
    && ((ff_info->stat.st_mode & S_IWGRP) == 0))
         ffblk->ff_attrib |= FA_RDONLY;
else if ((ff_info->stat.st_mode & S_IWOTH) == 0)
         ffblk->ff_attrib |= FA_RDONLY;

Code above was not tested (not even compiled) and was written from scratch
directly into mail. It won't check against supplementary groups, which it
should (to be perfect! :-) ).

But finally, my opinion is that those FA_* constants should be removed and
replaced with something like AA_FILE, AA_DIR (AA as Allegro attribute) and
maybe AA_HIDDEN. Those FA_RDONLY, FA_SYSTEM etc. are totally useless. Not
counting that for example on OS/2 you can define your own attributes (but
we have no OS/2 port, so don't mind).

Have a nice day.

Stepan Roh




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/