Ignore:
Timestamp:
Aug 28, 2009, 2:41:30 AM (15 years ago)
Author:
Bruno Cornec
Message:
  • Replacement of some fgets by mr_getline to allow for dyn. memory management.
  • Backport of SElinux fix from 2.2.9
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2349 r2351  
    313313    /*@ buffers **************************************************** */
    314314    char *program = NULL;
    315     char *incoming;
     315    char *incoming = NULL;
    316316    char *searchstr = NULL;
    317317    char *tmp = NULL;
     
    327327    assert_string_is_neither_NULL_nor_zerolength(drive);
    328328    assert(partno >= 0 && partno < 999);
    329 
    330     malloc_string(incoming);
    331329
    332330#ifdef __FreeBSD__
     
    356354    searchstr = build_partition_name(drive, partno);
    357355    mr_strcat(searchstr, " ");
    358     for (res = 0; !res && fgets(incoming, MAX_STR_LEN - 1, fin);) {
     356    for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
    359357        if (strstr(incoming, searchstr)) {
    360358            res = 1;
    361359        }
    362     }
     360        mr_free(incoming);
     361    }
     362    mr_free(incoming);
    363363    mr_free(searchstr);
    364364
     
    366366        log_OS_error("Cannot pclose fin");
    367367    }
    368     paranoid_free(incoming);
    369368    return (res);
    370369}
     
    567566    /*@ buffers ***************************************************** */
    568567    char *tmp = NULL;
    569     char *tmp1 = NULL;
    570568    char *output = NULL;
    571569    char *cdr_exe = NULL;
     
    634632    }
    635633
    636     malloc_string(tmp);
    637     tmp[0] = '\0';
    638     for ((void)fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
    639          (void)fgets(tmp, MAX_STR_LEN, fin)) {
     634    for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    640635        p = strchr(tmp, '\'');
    641636        if (p) {
     
    657652            }
    658653        }
    659     }
     654        mr_free(tmp);
     655    }
     656    mr_free(tmp);
    660657    paranoid_pclose(fin);
    661658
     
    671668            log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
    672669        } else {
    673             for ((void)fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
    674                  (void)fgets(tmp, MAX_STR_LEN, fin)) {
     670            for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    675671                log_msg(5, "--> '%s'", tmp);
    676672                if (tmp[0] != ' ' && tmp[1] != ' ') {
     
    688684                    }
    689685                }
     686                mr_free(tmp);
    690687            }
    691688            paranoid_pclose(fin);
     689            mr_free(tmp);
    692690        }
    693691    }
    694692    mr_free(phrase_two);
    695     paranoid_free(tmp);
    696693
    697694#endif
     
    725722
    726723    if (found_it) {
    727         mr_asprintf(tmp1, "grep \"%s=ide-scsi\" " CMDLINE " &> /dev/null", strrchr(output, '/') + 1);
    728         if (system(tmp1) == 0) {
     724        mr_asprintf(tmp, "grep \"%s=ide-scsi\" " CMDLINE " &> /dev/null", strrchr(output, '/') + 1);
     725        if (system(tmp) == 0) {
    729726            log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
    730727            found_it = FALSE;
    731728            mr_free(output);
    732729        }
    733         mr_free(tmp1);
     730        mr_free(tmp);
    734731    }
    735732
     
    772769            mr_free(output);
    773770        } else {
    774             mr_asprintf(tmp1, "%s/archives", mountpoint);
     771            mr_asprintf(tmp, "%s/archives", mountpoint);
    775772            if (!does_file_exist(tmp)) {
    776773                log_msg(4, "[Cardigans] I'll take it back");
     
    784781                log_msg(4, "I'm confident the Mondo CD is in %s", output);
    785782            }
    786             mr_free(tmp1);
     783            mr_free(tmp);
    787784        }
    788785    }
     
    808805
    809806    log_msg(1, "command=%s", command);
    810     mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command));
     807    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    811808    mr_free(command);
    812809
    813810    mr_free(output);
    814     if (strlen(tmp1) > 0) {
    815         mr_asprintf(output, "%s", tmp1);
     811    if (strlen(tmp) > 0) {
     812        mr_asprintf(output, "%s", tmp);
    816813        log_msg(4, "Finally found it at %s", output);
    817814    } else {
    818815        log_msg(4, "Still couldn't find it.");
    819816    }
    820     mr_free(tmp1);
     817    mr_free(tmp);
    821818
    822819    return (output);
     
    10261023
    10271024    /*@ buffers ***************************************************** */
    1028     char *incoming;
     1025    char *incoming = NULL;
    10291026    char *device_with_tab = NULL;
    10301027    char *device_with_space = NULL;
     
    10441041    }
    10451042
    1046     malloc_string(incoming);
    10471043    if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
    10481044        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
     
    10671063        return(FALSE);
    10681064    }
    1069     for ((void)fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    1070          (void)fgets(incoming, MAX_STR_LEN - 1, fin)) {
    1071         if (strstr(incoming, device_with_space) //> incoming
    1072             || strstr(incoming, device_with_tab))   // > incoming)
    1073         {
     1065
     1066    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     1067        if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) {
    10741068            paranoid_pclose(fin);
    1075             paranoid_free(incoming);
     1069            mr_free(incoming);
    10761070            return(TRUE);
    10771071        }
    1078     }
     1072        mr_free(incoming);
     1073    }
     1074    mr_free(incoming);
    10791075    mr_free(device_with_tab);
    10801076    mr_free(device_with_space);
     
    10861082    }
    10871083    mr_free(tmp);
    1088     paranoid_free(incoming);
    10891084    return(retval);
    10901085}
     
    23082303    char *list_drives_cmd = NULL;
    23092304    char *tmp = NULL;
    2310     char *current_drive;
     2305    char *current_drive = NULL;
    23112306
    23122307    /*@ pointers *************************************************** */
    2313     FILE *pdrives;
     2308    FILE *pdrives = NULL;
    23142309
    23152310    /*@ int ******************************************************** */
     
    23382333    }
    23392334
    2340     malloc_string(current_drive);
    2341     for ((void)fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
    2342          (void)fgets(current_drive, MAX_STR_LEN, pdrives)) {
    2343         strip_spaces(current_drive);
     2335    for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) {
     2336        mr_strip_spaces(current_drive);
    23442337        log_it("looking at drive %s's MBR", current_drive);
    23452338        if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
     
    23492342            mr_asprintf(which_device, "%s", current_drive);
    23502343            */
     2344            mr_free(current_drive);
    23512345            break;
    23522346        }
     
    23572351            mr_asprintf(which_device, "%s", current_drive);
    23582352            */
     2353            mr_free(current_drive);
    23592354            break;
    23602355        }
    2361     }
     2356        mr_free(current_drive);
     2357    }
     2358    mr_free(current_drive);
     2359
    23622360    if (pclose(pdrives)) {
    23632361        log_OS_error("Cannot pclose pdrives");
     
    23652363    log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
    23662364    if (count_grubs && !count_lilos) {
    2367         paranoid_free(current_drive);
    23682365        return ('G');
    23692366    } else if (count_lilos && !count_grubs) {
    2370         paranoid_free(current_drive);
    23712367        return ('L');
    23722368    } else if (count_grubs == 1 && count_lilos == 1) {
    23732369        log_it("I'll bet you used to use LILO but switched to GRUB...");
    2374         paranoid_free(current_drive);
    23752370        return ('G');
    23762371    } else {
     
    23822377            log_OS_error("Unable to open list of drives");
    23832378            mr_free(list_drives_cmd);
    2384             paranoid_free(current_drive);
    23852379            return ('\0');
    23862380        }
    23872381        mr_free(list_drives_cmd);
    23882382
    2389         for ((void)fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
    2390             (void)fgets(current_drive, MAX_STR_LEN, pdrives)) {
    2391             strip_spaces(current_drive);
     2383        for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) {
     2384            mr_strip_spaces(current_drive);
    23922385            log_it("looking at partition %s's BR", current_drive);
    23932386            if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
     
    23972390                mr_asprintf(which_device, "%s", current_drive);
    23982391                */
     2392                mr_free(current_drive);
    23992393                break;
    24002394            }
     
    24052399                mr_asprintf(which_device, "%s", current_drive);
    24062400                */
     2401                mr_free(current_drive);
    24072402                break;
    24082403            }
    2409         }
     2404            mr_free(current_drive);
     2405        }
     2406        mr_free(current_drive);
     2407
    24102408        if (pclose(pdrives)) {
    24112409            log_OS_error("Cannot pclose pdrives");
    24122410        }
    24132411        log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
    2414         paranoid_free(current_drive);
    24152412        if (count_grubs && !count_lilos) {
    24162413            return ('G');
Note: See TracChangeset for help on using the changeset viewer.