Changeset View
Changeset View
Standalone View
Standalone View
head/stand/liblua/lstd.c
Show All 25 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "lstd.h" | #include "lstd.h" | ||||
#include "math.h" | #include "math.h" | ||||
#ifdef LOADER_VERIEXEC | |||||
#include <verify_file.h> | |||||
#endif | |||||
FILE * | FILE * | ||||
fopen(const char *filename, const char *mode) | fopen(const char *filename, const char *mode) | ||||
{ | { | ||||
struct stat st; | struct stat st; | ||||
int fd, m, o; | int fd, m, o; | ||||
FILE *f; | FILE *f; | ||||
if (mode == NULL) | if (mode == NULL) | ||||
Show All 28 Lines | if (f == NULL) { | ||||
return NULL; | return NULL; | ||||
} | } | ||||
if (fstat(fd, &st) != 0) { | if (fstat(fd, &st) != 0) { | ||||
free(f); | free(f); | ||||
close(fd); | close(fd); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
#ifdef LOADER_VERIEXEC | |||||
/* only regular files and only reading makes sense */ | |||||
if (S_ISREG(st.st_mode) && !(m & O_WRONLY)) { | |||||
if (verify_file(fd, filename, 0, VE_GUESS) < 0) { | |||||
free(f); | |||||
close(fd); | |||||
return (NULL); | |||||
} | |||||
} | |||||
#endif | |||||
f->fd = fd; | f->fd = fd; | ||||
f->offset = 0; | f->offset = 0; | ||||
f->size = st.st_size; | f->size = st.st_size; | ||||
return (f); | return (f); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |