Ignore:
Timestamp:
Aug 18, 2009, 3:25:29 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3342@localhost: bruno | 2009-08-14 00:46:51 +0200

  • Another round of strcpy suppressions
  • find_home_of_exe() now allocates memory which has to be freed by the caller
  • Supress useless sz_last_suffix()
  • mr_getline now has the same interface as the other mr_mem functions
  • valgrind and compiler warnings fixes
File:
1 edited

Legend:

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

    r2328 r2331  
    317317 * @return The full path to the executable, or "" if it does not exist, or NULL if @c file could not be found.
    318318 * @note The returned string points to static storage that will be overwritten with each call.
    319  * @bug The checks with @c file and @c dirname seem pointless. If @c incoming is "", then you're calling
     319 * @bug The checks with @c file and @c dirname seem pointless. If @c output is "", then you're calling
    320320 * <tt>dirname 2\>/dev/null</tt> or <tt>file 2\>/dev/null | cut -d':' -f1 2\>/dev/null</tt>, which basically amounts
    321321 * to nothing.
     
    324324{
    325325    /*@ buffers ********************* */
    326     static char output[MAX_STR_LEN];
    327     char *incoming;
     326    char *output = NULL;
    328327    char *command = NULL;
    329328
    330     malloc_string(incoming);
    331     incoming[0] = '\0';
    332329    /*@******************************* */
    333330
    334331    assert_string_is_neither_NULL_nor_zerolength(fname);
    335332    mr_asprintf(command, "which %s 2> /dev/null", fname);
    336     strcpy(incoming, call_program_and_get_last_line_of_output(command));
    337     mr_free(command);
    338     if (incoming[0] == '\0') {
     333    mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command));
     334    mr_free(command);
     335    if (output[0] == '\0') {
    339336        if (system("which file > /dev/null 2> /dev/null")) {
    340             paranoid_free(incoming);
    341             output[0] = '\0';
     337            mr_free(output);
    342338            return (NULL);      // forget it :)
    343339        }
    344         mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
    345         strcpy(incoming, call_program_and_get_last_line_of_output(command));
     340        mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", output);
     341        mr_free(output);
     342        mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command));
    346343        mr_free(command);
    347344    }
    348     if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    349     {
    350         mr_asprintf(command, "dirname %s 2> /dev/null", incoming);
    351         strcpy(incoming, call_program_and_get_last_line_of_output(command));
     345    if (output[0] == '\0') {
     346        mr_asprintf(command, "dirname %s 2> /dev/null", output);
     347        mr_free(output);
     348        mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command));
    352349        mr_free(command);
    353350    }
    354     strcpy(output, incoming);
     351
    355352    if (output[0] != '\0' && does_file_exist(output)) {
    356         log_msg(4, "find_home_of_exe () --- Found %s at %s", fname,
    357                 incoming);
     353        log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, output);
    358354    } else {
    359         output[0] = '\0';
     355        mr_free(output);
    360356        log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
    361357    }
    362     paranoid_free(incoming);
    363     if (!output[0]) {
    364         return (NULL);
    365     } else {
    366         return (output);
    367     }
     358    return (output);
    368359}
    369360
     
    427418
    428419    /*@ buffers ***************************************************** */
    429     char lastline[MAX_STR_LEN];
     420    char *lastline = NULL;
    430421    char *command = NULL;
    431422    /*@ pointers **************************************************** */
     
    440431    if (i < 0) {
    441432        mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');
    442         strcpy(lastline, call_program_and_get_last_line_of_output(command));
     433        mr_asprintf(lastline, "%s", call_program_and_get_last_line_of_output(command));
    443434        mr_free(command);
    444435        if (!lastline[0]) {
     436            mr_free(lastline);
    445437            return (0);
    446438        }
    447439    } else {
    448         strcpy(lastline, err_log_lines[i]);
     440        mr_asprintf(lastline, "%s", err_log_lines[i]);
    449441    }
    450442
     
    454446    }
    455447    if (!p) {
     448        mr_free(lastline);
    456449        return (0);
    457450    }
     
    461454        p++;
    462455    }
     456    mr_free(lastline);
     457
    463458    i = atoi(p);
    464 
    465459    return (i);
    466460}
     
    550544    char stub_fname[1000];
    551545    char curr_fname[1000];
    552     char curr_cksum[1000];
     546    char *curr_cksum = NULL;
    553547    char *tmp = NULL;
    554548
     
    589583        mr_free(tmp);
    590584
    591         strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
     585        mr_asprintf(curr_cksum, "%s", calc_file_ugly_minichecksum(curr_fname));
    592586        fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
     587        mr_free(curr_cksum);
     588
    593589        if (counter++ > 12) {
    594590            current_time = get_time();
     
    719715    char *command = NULL;
    720716    char *mountlist = NULL;
    721     char sz_res[MAX_STR_LEN];
     717    char *sz_res = NULL;
    722718    long file_len_K;
    723719
     
    727723
    728724    log_it(command);
    729     strcpy(sz_res, call_program_and_get_last_line_of_output(command));
     725    mr_asprintf(sz_res, "%s", call_program_and_get_last_line_of_output(command));
    730726    file_len_K = atol(sz_res);
    731727    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     728    mr_free(sz_res);
    732729    mr_free(command);
    733730
     
    745742    char *fname;
    746743    char *biggielist = NULL;
    747     char *comment = NULL;
    748744    char *tmp = NULL;
    749745    char *command = NULL;
     
    752748    long scratchL = 0;
    753749    long file_len_K;
    754 
    755     int res = 0;
    756750
    757751    /*@ pointers *************************************************** */
     
    778772            if (0 == strncmp(fname, "/dev/", 5)) {
    779773                if (is_dev_an_NTFS_dev(fname)) {
    780                     if ( !find_home_of_exe("ntfsresize")) {
     774                    tmp = find_home_of_exe("ntfsresize");
     775                    if (!tmp) {
     776                        mr_free(tmp);
    781777                        fatal_error("ntfsresize not found");
    782778                    }
     779                    mr_free(tmp);
     780
    783781                    mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    784782                    log_it("command = %s", command);
     
    10051003    /*@ Char buffers ** */
    10061004    char *command = NULL;
    1007     char tmp[MAX_STR_LEN];
     1005    char *tmp = NULL;
    10081006    int res = 0;
    10091007
    1010     mvaddstr_and_log_it(g_currentY, 0,
    1011                         "Copying Mondo's core files to the scratch directory");
     1008    mvaddstr_and_log_it(g_currentY, 0, "Copying Mondo's core files to the scratch directory");
    10121009
    10131010    log_msg(4, "g_mondo_home='%s'", g_mondo_home);
     
    10331030    }
    10341031
    1035     strcpy(tmp,
    1036            call_program_and_get_last_line_of_output("which mondorestore"));
     1032    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("which mondorestore"));
    10371033    if (!tmp[0]) {
    1038         fatal_error
    1039             ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
     1034        mr_free(tmp);
     1035        fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    10401036    }
    10411037    mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1038    mr_free(tmp);
     1039
    10421040    res = run_program_and_log_output(command, FALSE);
    10431041    mr_free(command);
     
    12701268
    12711269/**
    1272  * Get the last suffix of @p instr.
    1273  * If @p instr was "httpd.log.gz", we would return "gz".
    1274  * @param instr The filename to get the suffix of.
    1275  * @return The suffix (without a dot), or "" if none.
    1276  * @note The returned string points to static storage that will be overwritten with each call.
    1277  */
    1278 char *sz_last_suffix(char *instr)
    1279 {
    1280     static char outstr[MAX_STR_LEN];
    1281     char *p;
    1282 
    1283     p = strrchr(instr, '.');
    1284     if (!p) {
    1285         outstr[0] = '\0';
    1286     } else {
    1287         strcpy(outstr, p);
    1288     }
    1289     return (outstr);
    1290 }
    1291 
    1292 
    1293 /**
    12941270 * Determine whether a file is compressed. This is done
    12951271 * by reading through the "do-not-compress-these" file distributed with Mondo.
     
    12991275bool is_this_file_compressed(char *filename)
    13001276{
    1301     char do_not_compress_these[MAX_STR_LEN];
     1277    char *do_not_compress_these = NULL;
    13021278    char *tmp = NULL;
    13031279    char *p;
     
    13151291    }
    13161292    /* BERLIOS: This is just plain WRONG !! */
    1317     strcpy(do_not_compress_these,last_line_of_file(tmp));
     1293    mr_asprintf(do_not_compress_these, "%s", last_line_of_file(tmp));
    13181294    mr_free(tmp);
    13191295
     
    13251301        if (!strcmp(q, tmp)) {
    13261302            mr_free(tmp);
     1303            mr_free(do_not_compress_these);
    13271304            return (TRUE);
    13281305        }
     
    13321309        mr_free(tmp);
    13331310    }
     1311    mr_free(do_not_compress_these);
    13341312    return (FALSE);
    13351313}
Note: See TracChangeset for help on using the changeset viewer.