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-filelist.c

    r2340 r2351  
    414414int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
    415415{
    416     FILE *pattr;
    417     char *tmp;
     416    FILE *pattr = NULL;
     417    char *tmp = NULL;
     418
    418419    pattr = popen(syscall, "r");
    419420    if (!pattr) {
     
    426427        return (2);
    427428    }
    428     malloc_string(tmp);
    429     for ((void)fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr);
    430          (void)fgets(tmp, MAX_STR_LEN, pattr)) {
     429    for (mr_getline(tmp, pattr); !feof(pattr); mr_getline(tmp, pattr)) {
    431430        fputs(tmp, pout);
    432     }
     431        mr_free(tmp);
     432    }
     433    mr_free(tmp);
    433434    paranoid_pclose(pattr);
    434     paranoid_free(tmp);
    435435    return (0);
    436436}
     
    441441                 char *auxlist_fname)
    442442{
    443     FILE *fin;
    444     FILE *pout;
     443    FILE *fin = NULL;
     444    FILE *pout = NULL;
    445445    char *pout_command = NULL;
    446     char *syscall;
    447     char *file_to_analyze;
     446    char *syscall = NULL;
     447    char *file_to_analyze = NULL;
    448448    char *strtmp = NULL;
    449449    char *tmp = NULL;
     
    463463    mr_free(pout_command);
    464464
    465     malloc_string(file_to_analyze);
    466     for ((void)fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);
    467          (void)fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     465    for (mr_getline(file_to_analyze, fin); !feof(fin); mr_getline(file_to_analyze, fin)) {
    468466        i = strlen(file_to_analyze);
    469467        if (i > 0 && file_to_analyze[i - 1] < 32) {
     
    478476        call_exe_and_pipe_output_to_fd(syscall, pout);
    479477        mr_free(syscall);
    480     }
     478        mr_free(file_to_analyze);
     479    }
     480    mr_free(file_to_analyze);
    481481    paranoid_fclose(fin);
    482482    paranoid_pclose(pout);
    483     paranoid_free(file_to_analyze);
    484483    return (0);
    485484}
     
    529528    char *syscall_pin = NULL;
    530529    char *syscall_pout = NULL;
    531     char *incoming;
    532     char *current_subset_file;
     530    char *incoming = NULL;
     531    char *current_subset_file = NULL;
    533532    char *current_master_file = NULL;
    534533    char *masklist = NULL;
     
    553552        return (0);
    554553    }
    555     malloc_string(incoming);
    556     malloc_string(current_subset_file);
    557554    mr_asprintf(masklist, "%s/masklist", bkpinfo->tmpdir);
    558555    mr_asprintf(command, "cp -f %s %s", orig_msklist, masklist);
     
    561558
    562559    sort_file(masklist);
    563     current_subset_file[0] = '\0';
    564560
    565561    mr_asprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
     
    594590//  printf("Hi there. Starting the loop\n");
    595591
    596     (void)fgets(current_subset_file, MAX_STR_LEN, faclin);
    597     (void)fgets(incoming, MAX_STR_LEN, pin);
     592    mr_getline(current_subset_file, faclin);
     593    mr_getline(incoming, pin);
    598594    while (!feof(pin) && !feof(faclin)) {
    599595        mr_asprintf(current_master_file, "%s", incoming + 8);
     
    625621        if (i < 0) {            // read another subset file in.
    626622            log_msg(my_depth, "Reading next subset line in\n\n");
    627             (void)fgets(current_subset_file, MAX_STR_LEN, faclin);
     623            mr_free(current_subset_file);
     624            mr_getline(current_subset_file, faclin);
    628625            continue;
    629626        }
     
    632629            fputs(incoming, pout);
    633630        }
    634         (void)fgets(incoming, MAX_STR_LEN, pin);
     631        mr_free(incoming);
     632        mr_getline(incoming, pin);
    635633        if (!i) {
    636634            log_msg(my_depth, "Copying master %s", q);
     
    641639                fputs(incoming, pout);
    642640            }
    643             (void)fgets(incoming, MAX_STR_LEN, pin);
     641            mr_free(incoming);
     642            mr_getline(incoming, pin);
    644643        }
    645644        if (!i) {
    646             (void)fgets(current_subset_file, MAX_STR_LEN, faclin);
     645            mr_free(current_subset_file);
     646            mr_getline(current_subset_file, faclin);
    647647        }
    648648        mr_free(current_master_file);
    649649    }
    650     while (!feof(pin)) {
    651         (void)fgets(incoming, MAX_STR_LEN, pin);
    652     }
     650    mr_free(current_subset_file);
     651    mr_free(incoming);
    653652    fclose(faclin);
    654653    pclose(pin);
    655654    pclose(pout);
    656655
    657 //  printf("OK, loop is done\n");
    658 
    659656    unlink(masklist);
    660657    mr_free(masklist);
    661658
    662     paranoid_free(current_subset_file);
    663     paranoid_free(incoming);
    664659    return (retval);
    665660}
     
    772767    noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    773768
    774 /* walk across tree if necessary */
     769    /* walk across tree if necessary */
    775770    node = startnode;
    776771    char_to_add = string_to_add[0];
     
    781776    }
    782777
    783 /* walk down tree if appropriate */
     778    /* walk down tree if appropriate */
    784779    if (node->down != NULL && node->ch == char_to_add) {
    785780        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     
    795790    }
    796791
    797 /* add here */
     792    /* add here */
    798793    if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
    799794        log_to_screen("failed to malloc");
     
    866861    /*@ buffers **************************************************** */
    867862    char *command_to_open_fname = NULL;
    868     char fname[MAX_STR_LEN];
    869     char tmp[MAX_STR_LEN];
    870     char *tmp1 = NULL;
     863    char *fname = NULL;
     864    char *tmp = NULL;
    871865    int pos_in_fname;
    872866    /*@ int ******************************************************** */
     
    884878    }
    885879    log_to_screen("Loading filelist");
    886     mr_asprintf(tmp1, "zcat %s | wc -l", filelist_fname);
    887     log_msg(6, "tmp1 = %s", tmp1);
    888     lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp1));
    889     mr_free(tmp1);
     880    mr_asprintf(tmp, "zcat %s | wc -l", filelist_fname);
     881    log_msg(6, "tmp = %s", tmp);
     882    lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp));
     883    mr_free(tmp);
    890884
    891885    if (lines_in_filelist < 3) {
     
    913907
    914908    open_evalcall_form("Loading filelist from disk");
    915     for ((void)fgets(fname, MAX_STR_LEN, pin); !feof(pin);
    916          (void)fgets(fname, MAX_STR_LEN, pin)) {
    917         if ((fname[strlen(fname) - 1] == 13
    918              || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) {
     909    for (mr_getline(fname, pin); !feof(pin); mr_getline(fname, pin)) {
     910        if ((strlen(fname) > 0) && (fname[strlen(fname) - 1] == 13 || fname[strlen(fname) - 1] == 10)) {
    919911            fname[strlen(fname) - 1] = '\0';
    920912        }
    921 //      strip_spaces (fname);
    922913        if (!strlen(fname)) {
     914            mr_free(fname);
    923915            continue;
    924916        }
     
    927919                continue;
    928920            }
    929             strcpy(tmp, fname);
     921            mr_asprintf(tmp, "%s", fname);
    930922            tmp[pos_in_fname] = '\0';
    931923            if (strlen(tmp)) {
    932924                add_string_at_node(filelist, tmp);
    933925            }
     926            mr_free(tmp);
    934927        }
    935928        add_string_at_node(filelist, fname);
     929        mr_free(fname);
     930
    936931        if (!(++lino % 1111)) {
    937932            percentage = (int) (lino * 100 / lines_in_filelist);
     
    939934        }
    940935    }
     936    mr_free(fname);
     937
    941938    paranoid_pclose(pin);
    942939    close_evalcall_form();
     
    18351832                                  char *list_of_files_fname, bool flag_em)
    18361833{
    1837     FILE *fin;
    1838     char *tmp;
    1839     struct s_node *nod;
    1840 
    1841     malloc_string(tmp);
     1834    FILE *fin = NULL;
     1835    char *tmp = NULL;
     1836    struct s_node *nod = NULL;
     1837
    18421838    log_msg(3, "Adding %s to filelist", list_of_files_fname);
    18431839    if (!(fin = fopen(list_of_files_fname, "r"))) {
     
    18451841        return (1);
    18461842    }
    1847     for ((void)fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
    1848          (void)fgets(tmp, MAX_STR_LEN, fin)) {
     1843    for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    18491844        if (!tmp[0]) {
     1845            mr_free(tmp);
    18501846            continue;
    18511847        }
    1852         if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
    1853             && strlen(tmp) > 0) {
     1848        if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)) {
    18541849            tmp[strlen(tmp) - 1] = '\0';
    18551850        }
    18561851        log_msg(2, "tmp = '%s'", tmp);
    18571852        if (!tmp[0]) {
     1853            mr_free(tmp);
    18581854            continue;
    18591855        }
     
    18691865            log_msg(5, "Flagged '%s'", tmp);
    18701866        }
    1871     }
     1867        mr_free(tmp);
     1868    }
     1869    mr_free(tmp);
    18721870    paranoid_fclose(fin);
    1873     paranoid_free(tmp);
    18741871    return (0);
    18751872}
Note: See TracChangeset for help on using the changeset viewer.