Add "close on exec" flag to all open() calls
This commit is contained in:
		@@ -109,7 +109,7 @@ static px_type *load_png(const char *path, int destW, int destH)
 | 
			
		||||
    uint32_t src_pix;
 | 
			
		||||
    png_bytep *rows = NULL;
 | 
			
		||||
 | 
			
		||||
    fp = fopen(path, "rb");
 | 
			
		||||
    fp = fopen(path, "rbe");
 | 
			
		||||
    if(!fp)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
@@ -325,7 +325,7 @@ int fb_png_save_img(const char *path, int w, int h, int stride, px_type *data)
 | 
			
		||||
    const int w_png_bytes = w * 3;
 | 
			
		||||
    px_type * volatile itr = data;
 | 
			
		||||
 | 
			
		||||
    fp = fopen(path, "w");
 | 
			
		||||
    fp = fopen(path, "we");
 | 
			
		||||
    if(!fp)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open %s for writing\n", path);
 | 
			
		||||
 
 | 
			
		||||
@@ -99,7 +99,7 @@ static void *fb_qcom_vsync_thread_work(void *data)
 | 
			
		||||
    struct timespec now;
 | 
			
		||||
    char buff[64];
 | 
			
		||||
 | 
			
		||||
    fd = open("/sys/class/graphics/fb0/vsync_event", O_RDONLY);
 | 
			
		||||
    fd = open("/sys/class/graphics/fb0/vsync_event", O_RDONLY | O_CLOEXEC);
 | 
			
		||||
    if(fd < 0)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Unable to open vsync_event!\n");
 | 
			
		||||
@@ -216,7 +216,7 @@ static int map_mdp_pixel_format()
 | 
			
		||||
static void setDisplaySplit(struct fb_qcom_overlay_data *data)
 | 
			
		||||
{
 | 
			
		||||
    char split[64] = { 0 };
 | 
			
		||||
    FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
 | 
			
		||||
    FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "re");
 | 
			
		||||
    if(fp)
 | 
			
		||||
    {
 | 
			
		||||
        //Format "left right" space as delimiter
 | 
			
		||||
 
 | 
			
		||||
@@ -63,7 +63,7 @@ struct fstab *fstab_create_empty(int version)
 | 
			
		||||
 | 
			
		||||
struct fstab *fstab_load(const char *path, int resolve_symlinks)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f = fopen(path, "r");
 | 
			
		||||
    FILE *f = fopen(path, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open fstab %s\n", path);
 | 
			
		||||
@@ -181,7 +181,7 @@ int fstab_save(struct fstab *f, const char *path)
 | 
			
		||||
    FILE *out;
 | 
			
		||||
    struct fstab_part *p;
 | 
			
		||||
 | 
			
		||||
    out = fopen(path, "w");
 | 
			
		||||
    out = fopen(path, "we");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("fstab_save: failed to open %s!", path);
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ static int inject_rd(const char *path)
 | 
			
		||||
    int result = -1;
 | 
			
		||||
    uint32_t magic = 0;
 | 
			
		||||
 | 
			
		||||
    FILE *f = fopen(path, "r");
 | 
			
		||||
    FILE *f = fopen(path, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Couldn't open %s!\n", path);
 | 
			
		||||
 
 | 
			
		||||
@@ -244,11 +244,11 @@ int wait_for_file(const char *filename, int timeout)
 | 
			
		||||
 | 
			
		||||
int copy_file(const char *from, const char *to)
 | 
			
		||||
{
 | 
			
		||||
    FILE *in = fopen(from, "r");
 | 
			
		||||
    FILE *in = fopen(from, "re");
 | 
			
		||||
    if(!in)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    FILE *out = fopen(to, "w");
 | 
			
		||||
    FILE *out = fopen(to, "we");
 | 
			
		||||
    if(!out)
 | 
			
		||||
    {
 | 
			
		||||
        fclose(in);
 | 
			
		||||
@@ -509,7 +509,7 @@ static int remount_ro_done(void)
 | 
			
		||||
    int match;
 | 
			
		||||
    int found_rw_fs = 0;
 | 
			
		||||
 | 
			
		||||
    f = fopen("/proc/mounts", "r");
 | 
			
		||||
    f = fopen("/proc/mounts", "re");
 | 
			
		||||
    if (! f) {
 | 
			
		||||
        /* If we can't read /proc/mounts, just give up */
 | 
			
		||||
        return 1;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										32
									
								
								multirom.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								multirom.c
									
									
									
									
									
								
							@@ -476,7 +476,7 @@ int multirom_load_status(struct multirom_status *s)
 | 
			
		||||
    char arg[256];
 | 
			
		||||
    sprintf(arg, "%s/multirom.ini", mrom_dir());
 | 
			
		||||
 | 
			
		||||
    FILE *f = fopen(arg, "r");
 | 
			
		||||
    FILE *f = fopen(arg, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open config file, using defaults!\n");
 | 
			
		||||
@@ -494,7 +494,7 @@ int multirom_load_status(struct multirom_status *s)
 | 
			
		||||
        s->is_second_boot = 1;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        FILE *cmdline = fopen("/proc/cmdline", "r");
 | 
			
		||||
        FILE *cmdline = fopen("/proc/cmdline", "re");
 | 
			
		||||
        if(cmdline)
 | 
			
		||||
        {
 | 
			
		||||
            if(fgets(line, sizeof(line), cmdline) && strstr(line, "mrom_kexecd=1"))
 | 
			
		||||
@@ -612,7 +612,7 @@ int multirom_save_status(struct multirom_status *s)
 | 
			
		||||
 | 
			
		||||
    snprintf(path, sizeof(path), "%s/multirom.ini", mrom_dir());
 | 
			
		||||
 | 
			
		||||
    FILE *f = fopen(path, "w");
 | 
			
		||||
    FILE *f = fopen(path, "we");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open/create status file!\n");
 | 
			
		||||
@@ -904,7 +904,7 @@ void multirom_import_internal(void)
 | 
			
		||||
    snprintf(path, sizeof(path), "%s/roms/%s/.icon_data", mrom_dir(), INTERNAL_ROM_NAME);
 | 
			
		||||
    if(access(path, F_OK) < 0)
 | 
			
		||||
    {
 | 
			
		||||
        FILE *f = fopen(path, "w");
 | 
			
		||||
        FILE *f = fopen(path, "we");
 | 
			
		||||
        if(f)
 | 
			
		||||
        {
 | 
			
		||||
            fputs("predef_set\ncom.tassadar.multirommgr:drawable/romic_android\n", f);
 | 
			
		||||
@@ -1017,7 +1017,7 @@ int multirom_prepare_for_boot(struct multirom_status *s, struct multirom_rom *to
 | 
			
		||||
 | 
			
		||||
char *multirom_find_fstab_in_rc(const char *rcfile)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f = fopen(rcfile, "r");
 | 
			
		||||
    FILE *f = fopen(rcfile, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open rcfile %s\n", rcfile);
 | 
			
		||||
@@ -1079,7 +1079,7 @@ static int multirom_inject_fw_mounter(char *rc_with_mount_all, struct fstab_part
 | 
			
		||||
    char *rc_file, *p;
 | 
			
		||||
    size_t rc_len, alloc_size;
 | 
			
		||||
    char line[512];
 | 
			
		||||
    FILE *f = fopen(rc_with_mount_all, "r+");
 | 
			
		||||
    FILE *f = fopen(rc_with_mount_all, "r+e");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open file \"%s\" to inject fw_mounter!", rc_with_mount_all);
 | 
			
		||||
@@ -1386,7 +1386,7 @@ int multirom_create_media_link(void)
 | 
			
		||||
        char buf[16];
 | 
			
		||||
        buf[0] = 0;
 | 
			
		||||
 | 
			
		||||
        FILE *f = fopen(LAYOUT_VERSION, "r");
 | 
			
		||||
        FILE *f = fopen(LAYOUT_VERSION, "re");
 | 
			
		||||
        const int rewrite = (!f || !fgets(buf, sizeof(buf), f) || atoi(buf) < 2);
 | 
			
		||||
 | 
			
		||||
        if(f)
 | 
			
		||||
@@ -1394,7 +1394,7 @@ int multirom_create_media_link(void)
 | 
			
		||||
 | 
			
		||||
        if(rewrite)
 | 
			
		||||
        {
 | 
			
		||||
            f = fopen(LAYOUT_VERSION, "w");
 | 
			
		||||
            f = fopen(LAYOUT_VERSION, "we");
 | 
			
		||||
            if(!f)
 | 
			
		||||
            {
 | 
			
		||||
                ERROR("Failed to create .layout_version!\n");
 | 
			
		||||
@@ -1412,7 +1412,7 @@ int multirom_create_media_link(void)
 | 
			
		||||
 | 
			
		||||
int multirom_get_api_level(const char *path)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f = fopen(path, "r");
 | 
			
		||||
    FILE *f = fopen(path, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Could not open %s to read api level!", path);
 | 
			
		||||
@@ -1535,7 +1535,7 @@ int multirom_get_bootloader_cmdline(struct multirom_status *s, char *str, size_t
 | 
			
		||||
    struct boot_img_hdr hdr;
 | 
			
		||||
    struct fstab_part *boot;
 | 
			
		||||
 | 
			
		||||
    f = fopen("/proc/cmdline", "r");
 | 
			
		||||
    f = fopen("/proc/cmdline", "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
@@ -1887,7 +1887,7 @@ struct rom_info *multirom_parse_rom_info(struct multirom_status *s, struct multi
 | 
			
		||||
    sprintf(path, "%s/rom_info.txt", rom->base_path);
 | 
			
		||||
    ERROR("Parsing %s...\n", path);
 | 
			
		||||
 | 
			
		||||
    FILE *f = fopen(path, "r");
 | 
			
		||||
    FILE *f = fopen(path, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open %s!\n", path);
 | 
			
		||||
@@ -2164,7 +2164,7 @@ int multirom_replace_aliases_root_path(char **s, struct multirom_rom *rom)
 | 
			
		||||
 | 
			
		||||
int multirom_extract_bytes(const char *dst, FILE *src, size_t size)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f = fopen(dst, "w");
 | 
			
		||||
    FILE *f = fopen(dst, "we");
 | 
			
		||||
    if(!f)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open dest file %s\n", dst);
 | 
			
		||||
@@ -2398,7 +2398,7 @@ int multirom_copy_log(char *klog, const char *dest_path_relative)
 | 
			
		||||
    {
 | 
			
		||||
        char path[256];
 | 
			
		||||
        snprintf(path, sizeof(path), "%s/%s", mrom_dir(), dest_path_relative);
 | 
			
		||||
        FILE *f = fopen(path, "w");
 | 
			
		||||
        FILE *f = fopen(path, "we");
 | 
			
		||||
 | 
			
		||||
        if(f)
 | 
			
		||||
        {
 | 
			
		||||
@@ -2434,7 +2434,7 @@ struct usb_partition *multirom_get_partition(struct multirom_status *s, char *uu
 | 
			
		||||
 | 
			
		||||
int multirom_search_last_kmsg(const char *expr)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f = fopen("/proc/last_kmsg", "r");
 | 
			
		||||
    FILE *f = fopen("/proc/last_kmsg", "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
@@ -2458,7 +2458,7 @@ int multirom_get_battery(void)
 | 
			
		||||
{
 | 
			
		||||
    char buff[4];
 | 
			
		||||
 | 
			
		||||
    FILE *f = fopen(BATTERY_CAP, "r");
 | 
			
		||||
    FILE *f = fopen(BATTERY_CAP, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
@@ -2507,7 +2507,7 @@ void multirom_find_rom_icon(struct multirom_rom *rom)
 | 
			
		||||
 | 
			
		||||
    snprintf(buff, sizeof(buff), "%s/.icon_data", rom->base_path);
 | 
			
		||||
 | 
			
		||||
    f = fopen(buff, "r");
 | 
			
		||||
    f = fopen(buff, "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
        goto fail;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -101,7 +101,7 @@ static void workaround_rc_restorecon(const char *rc_file_name)
 | 
			
		||||
    char *r;
 | 
			
		||||
    int changed = 0;
 | 
			
		||||
 | 
			
		||||
    f_in = fopen(rc_file_name, "r");
 | 
			
		||||
    f_in = fopen(rc_file_name, "re");
 | 
			
		||||
    if(!f_in)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open input file %s\n", rc_file_name);
 | 
			
		||||
@@ -111,7 +111,7 @@ static void workaround_rc_restorecon(const char *rc_file_name)
 | 
			
		||||
    name_out = malloc(strlen(rc_file_name)+5);
 | 
			
		||||
    snprintf(name_out, strlen(rc_file_name)+5, "%s.new", rc_file_name);
 | 
			
		||||
 | 
			
		||||
    f_out = fopen(name_out, "w");
 | 
			
		||||
    f_out = fopen(name_out, "we");
 | 
			
		||||
    if(!f_out)
 | 
			
		||||
    {
 | 
			
		||||
        ERROR("Failed to open output file %s\n", name_out);
 | 
			
		||||
@@ -163,14 +163,14 @@ static void workaround_mount_in_sh(const char *path)
 | 
			
		||||
    char *tmp_name = NULL;
 | 
			
		||||
    FILE *f_in, *f_out;
 | 
			
		||||
 | 
			
		||||
    f_in = fopen(path, "r");
 | 
			
		||||
    f_in = fopen(path, "re");
 | 
			
		||||
    if(!f_in)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    const int size = strlen(path) + 5;
 | 
			
		||||
    tmp_name = malloc(size);
 | 
			
		||||
    snprintf(tmp_name, size, "%s-new", path);
 | 
			
		||||
    f_out = fopen(tmp_name, "w");
 | 
			
		||||
    f_out = fopen(tmp_name, "we");
 | 
			
		||||
    if(!f_out)
 | 
			
		||||
    {
 | 
			
		||||
        fclose(f_in);
 | 
			
		||||
 
 | 
			
		||||
@@ -203,7 +203,7 @@ void adb_cleanup(void)
 | 
			
		||||
 | 
			
		||||
int adb_get_serial(char *serial, int maxlen)
 | 
			
		||||
{
 | 
			
		||||
    FILE *f = fopen("/proc/cmdline", "r");
 | 
			
		||||
    FILE *f = fopen("/proc/cmdline", "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -919,7 +919,7 @@ try_loading_again:
 | 
			
		||||
    if(fw_fd < 0) {
 | 
			
		||||
        fw_fd = open(file2, O_RDONLY | O_CLOEXEC);
 | 
			
		||||
        if (fw_fd < 0) {
 | 
			
		||||
            fw_fd = open(file3, O_RDONLY);
 | 
			
		||||
            fw_fd = open(file3, O_RDONLY | O_CLOEXEC);
 | 
			
		||||
            if (fw_fd < 0) {
 | 
			
		||||
                if (booting) {
 | 
			
		||||
                        /* If we're not fully booted, we may be missing
 | 
			
		||||
 
 | 
			
		||||
@@ -203,7 +203,7 @@ static int is_charger_mode(void)
 | 
			
		||||
{
 | 
			
		||||
    char buff[2048] = { 0 };
 | 
			
		||||
 | 
			
		||||
    FILE *f = fopen("/proc/cmdline", "r");
 | 
			
		||||
    FILE *f = fopen("/proc/cmdline", "re");
 | 
			
		||||
    if(!f)
 | 
			
		||||
        return 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user