Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: EXP37 compliance

...

Code Block
bgColor#ccccff
struct stat orig_st;
struct stat new_st;
char *file_name;

/* initialize file_name */

int fd = open(file_name, O_WRONLY, S_IRWXU);
if (fd == -1) {
  /* handle Error */
}

/*... write to file ...*/

if (fstat(fd, &orig_st) == -1) {
  /* handle error */
}
close(fd);
fd = -1;

/* ... */

fd = open(file_name, O_RDONLY, S_IRWXU);
if (fd == -1) {
  /* handle error */
}

if (fstat(fd, &new_st) == -1) {
  /* handle error */
}

if ((orig_st.st_dev != new_st.st_dev) ||
    (orig_st.st_ino != new_st.st_ino)) {
  /* file was tampered with! */
}

/*... read from file ...*/

close(fd);
fd = -1;

...

Code Block
bgColor#ccccff
struct stat st;
char *file_name;

/* initialize file_name */

int fd = open(file_name, O_RDONLY, S_IRWXU);
if (fd == -1) {
  /* Handle Error */
}

if ((fstat(fd, &st) == -1) ||
   (st.st_uid != getuid()) ||
   (st.st_gid != getgid())) {
  /* file does not belong to user */
}

/*... read from file ...*/

close(fd);
fd = -1;

...