Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Apr 2013 20:29:52 +0200
From:      =?iso-8859-1?Q?P=E9tur_Ingi_Egilsson?= <petur@petur.eu>
To:        freebsd-security@freebsd.org
Subject:   File descriptors
Message-ID:  <B4285FA7-E3EF-4639-BFC0-9BEA7881A5CB@petur.eu>

next in thread | raw e-mail | index | archive | help
I noticed that if I execute the following code, then the program is able =
to read the file even if the files' permissions are changed around the =
/mark/ section in such a way that the UID under which the program is =
running should not have any permission to read the file.

This is not a desirable behaviour.
How can I prevent this behaviour on my system?


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
    if (argc !=3D 2) {
            printf("Usage: %s filename\n", argv[0]);
            exit(EXIT_FAILURE);
    }

   FILE *fd;
   char *line =3D NULL;
   size_t len =3D 0;

   fd =3D fopen(argv[2], "r");

    /* mark */

    if (fd =3D=3D NULL) {
            exit(EXIT_FAILURE);
    }

    while (getline(&line, &len, fd) !=3D -1) {
       printf("%s", line);
   }
    fclose(fd);
   exit(EXIT_SUCCESS);
}




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B4285FA7-E3EF-4639-BFC0-9BEA7881A5CB>