Changeset 2330 in MondoRescue


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

r3341@localhost: bruno | 2009-08-13 22:36:24 +0200

  • Replacement of some strcpy
  • Change allocation done in resolve_softlinks_to_get_to_actual_device_file(), where_is_root_mounted(), bkptype_to_string(), which_boot_loader()
Location:
branches/2.2.10/mondo/src
Files:
6 edited

Legend:

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

    r2328 r2330  
    25592559 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
    25602560 */
    2561 int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
    2562                                              bool keep_looping)
    2563 {
     2561int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev, bool keep_looping) {
    25642562    int res = 0;
    25652563    char *bkp = NULL;
     
    28232821    /*@ buffers ************************************************** */
    28242822    char *tmp = NULL;
    2825     char *checksum_line, *command;
     2823    char *checksum_line = NULL;
     2824    char *command;
    28262825    char *tempblock;
    28272826    char *curr_slice_fname_uncompressed = NULL;
     
    28592858    assert(bkpinfo != NULL);
    28602859    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    2861     malloc_string(checksum_line);
    28622860
    28632861    biggiestruct.for_backward_compatibility = '\n';
     
    28772875    if (ntfsprog_fifo) {
    28782876        file_to_openin = ntfsprog_fifo;
    2879         strcpy(checksum_line, "IGNORE");
    2880         log_msg(2,
    2881                 "Not calculating checksum for %s: it would take too long",
    2882                 biggie_filename);
     2877        mr_asprintf(checksum_line, "IGNORE");
     2878        log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
    28832879        if ( !find_home_of_exe("ntfsresize")) {
    28842880            fatal_error("ntfsresize not found");
     
    29042900        }
    29052901        mr_free(command);
    2906         (void) fgets(checksum_line, MAX_STR_LEN, fin);
     2902        mr_getline(checksum_line, fin);
    29072903        pclose(fin);
    29082904        totallength = length_of_file (biggie_filename);
     
    29182914    }
    29192915    strcpy(biggiestruct.checksum, checksum_line);
     2916    mr_free(checksum_line);
    29202917
    29212918    mr_asprintf(tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     
    29402937        log_to_screen("Cannot archive bigfile '%s': not found", biggie_filename);
    29412938
    2942         paranoid_free(checksum_line);
    29432939        mr_free(suffix);
    29442940        return (1);
     
    30743070    mr_free(tmp);
    30753071
    3076     paranoid_free(checksum_line);
    30773072    return (retval);
    30783073}
  • branches/2.2.10/mondo/src/common/libmondo-cli.c

    r2328 r2330  
    908908        }
    909909        if (!flag_set['d']) {
    910             if ((tmp = find_dvd_device(flag_val['d'])) != NULL) {
    911                 strcpy(flag_val['d'],tmp);
    912                 mr_free(tmp);
     910            if ((tmp1 = find_dvd_device(flag_val['d'])) != NULL) {
     911                strcpy(flag_val['d'],tmp1);
     912                mr_free(tmp1);
    913913                flag_set['d'] = TRUE;
    914914                log_to_screen("I guess DVD drive is at %s", flag_val['d']);
     
    13231323    if (flag_set['f']) {
    13241324        mr_free(bkpinfo->boot_device);
    1325         mr_asprintf(bkpinfo->boot_device, "%s", resolve_softlinks_to_get_to_actual_device_file(flag_val['f']));
     1325        bkpinfo->boot_device = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
    13261326    }
    13271327
     
    13321332
    13331333    if (flag_set['Q']) {
    1334         i = which_boot_loader(tmp);
    1335         log_msg(3, "boot loader is %c, residing at %s", i, tmp);
    1336         printf("boot loader is %c, residing at %s\n", i, tmp);
     1334        i = which_boot_loader(tmp1);
     1335        log_msg(3, "boot loader is %c, residing at %s", i, tmp1);
     1336        printf("boot loader is %c, residing at %s\n", i, tmp1);
     1337        mr_free(tmp1);
    13371338        finish(0);
    13381339    }
  • branches/2.2.10/mondo/src/common/libmondo-devices-EXT.h

    r2325 r2330  
    6161extern int inject_device(char *dev);
    6262extern bool does_nonMS_partition_exist(void);
    63 extern char *resolve_softlinks_to_get_to_actual_device_file(char
    64                                                             *incoming);
     63extern char *resolve_softlinks_to_get_to_actual_device_file(char *incoming);
    6564
    6665extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value();
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2329 r2330  
    112112    bool is_this_a_ramdisk = FALSE;
    113113
    114     mr_asprintf(tmp, "%s", where_is_root_mounted());
     114    tmp = where_is_root_mounted();
    115115    log_msg(0, "root is currently mounted at %s\n", tmp);
    116116
     
    156156static char *bkptype_to_string(t_bkptype bt)
    157157{
    158     static char output[MAX_STR_LEN / 4];
     158    char *output;
    159159    switch (bt) {
    160160    case none:
    161         strcpy(output, "none");
     161        mr_asprintf(output, "none");
    162162        break;
    163163    case iso:
    164         strcpy(output, "iso");
     164        mr_asprintf(output, "iso");
    165165        break;
    166166    case cdr:
    167         strcpy(output, "cdr");
     167        mr_asprintf(output, "cdr");
    168168        break;
    169169    case cdrw:
    170         strcpy(output, "cdrw");
     170        mr_asprintf(output, "cdrw");
    171171        break;
    172172    case cdstream:
    173         strcpy(output, "cdstream");
     173        mr_asprintf(output, "cdstream");
    174174        break;
    175175    case nfs:
    176         strcpy(output, "nfs");
     176        mr_asprintf(output, "nfs");
    177177        break;
    178178    case tape:
    179         strcpy(output, "tape");
     179        mr_asprintf(output, "tape");
    180180        break;
    181181    case udev:
    182         strcpy(output, "udev");
     182        mr_asprintf(output, "udev");
    183183        break;
    184184    case usb:
    185         strcpy(output, "usb");
     185        mr_asprintf(output, "usb");
    186186        break;
    187187    default:
    188         strcpy(output, "default");
     188        mr_asprintf(output, "default");
    189189    }
    190190    return (output);
     
    572572    char *output = NULL;
    573573    char *cdr_exe = NULL;
    574     char *phrase_one = NULL;
    575574    char *phrase_two = NULL;
    576575    char *command = NULL;
     
    634633    }
    635634
    636     malloc_string(phrase_one);
    637     phrase_one[0] = '\0';
    638     malloc_string(phrase_two);
    639     phrase_two[0] = '\0';
    640 
    641635    malloc_string(tmp);
    642636    tmp[0] = '\0';
     
    649643                for (r = q; *(r - 1) == ' '; r--);
    650644                *r = '\0';
    651                 strcpy(phrase_one, p);
    652645                p = strchr(++q, '\'');
    653646                if (p) {
     
    658651                        }
    659652                        *q = '\0';
    660                         strcpy(phrase_two, p);
     653                        mr_asprintf(phrase_two, "%s", p);
    661654                    }
    662655                }
     
    665658    }
    666659    paranoid_pclose(fin);
    667     paranoid_free(phrase_one);
    668660
    669661#ifndef __FreeBSD__
    670     if (strlen(phrase_two) == 0) {
     662    if (!phrase_two || strlen(phrase_two) == 0) {
    671663        log_msg(4, "Not running phase two. String is empty.");
    672664    } else {
     
    699691        }
    700692    }
    701     paranoid_free(phrase_two);
     693    mr_free(phrase_two);
    702694    paranoid_free(tmp);
    703695
     
    14381430    }
    14391431    */
    1440     log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
     1432    tmp = bkptype_to_string(bkpinfo->backup_media_type);
     1433    log_msg(3, "media type = %s", tmp);
     1434    mr_free(tmp);
     1435
    14411436    bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
    1442     bkpinfo->compression_level =
    1443         (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
    1444     bkpinfo->use_lzo =
    1445         (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
     1437    bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
     1438    bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
    14461439    mvaddstr_and_log_it(2, 0, " ");
    14471440
     
    19731966    log_it("media device = %s", bkpinfo->media_device);
    19741967    log_it("media size = %ld", bkpinfo->media_size[1]);
    1975     log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
     1968    tmp = bkptype_to_string(bkpinfo->backup_media_type);
     1969    log_it("media type = %s", tmp);
     1970    mr_free(tmp);
     1971
    19761972    if (bkpinfo->prefix) {
    19771973        log_it("prefix = %s", bkpinfo->prefix);
     
    22352231 * The mountpoint (where it's mounted) will obviously be '/'.
    22362232 */
    2237 char *where_is_root_mounted()
    2238 {
     2233char *where_is_root_mounted() {
    22392234    /*@ buffers **************** */
    2240     static char tmp[MAX_STR_LEN];
     2235    char *output;
    22412236
    22422237
    22432238#ifdef __FreeBSD__
    2244     strcpy(tmp, call_program_and_get_last_line_of_output
    2245            ("mount | grep \" on / \" | cut -d' ' -f1"));
     2239    mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1"));
    22462240#else
    2247     strcpy(tmp, call_program_and_get_last_line_of_output
    2248            ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
    2249     if (strstr(tmp, "/dev/cciss/")) {
    2250         strcpy(tmp, call_program_and_get_last_line_of_output
    2251                ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
    2252     }
    2253     if (strstr(tmp, "/dev/md")) {
    2254         strcpy(tmp,
    2255                call_program_and_get_last_line_of_output
    2256                ("mount | grep \" on / \" | cut -d' ' -f1"));
    2257     }
    2258 #endif
    2259 
    2260     return (tmp);
     2241    mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
     2242    if (strstr(output, "/dev/cciss/")) {
     2243        mr_free(output);
     2244        mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
     2245    }
     2246    if (strstr(output, "/dev/md")) {
     2247        mr_free(output);
     2248        mr_asprintf(output, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1"));
     2249    }
     2250#endif
     2251
     2252    return (output);
    22612253}
    22622254
     
    22692261 */
    22702262#ifdef __FreeBSD__
    2271 char which_boot_loader(char *which_device)
    2272 {
     2263char which_boot_loader(char *which_device) {
    22732264    int count_lilos = 0;
    22742265    int count_grubs = 0;
     
    22862277        count_boot0s++;
    22872278    }
    2288     if (does_string_exist_in_first_N_blocks
    2289         (which_device, "FreeBSD/i386", 17)) {
     2279    if (does_string_exist_in_first_N_blocks(which_device, "FreeBSD/i386", 17)) {
    22902280        count_dangerouslydedicated++;
    22912281    }
     
    23132303#else
    23142304
    2315 char which_boot_loader(char *which_device)
    2316 {
     2305char which_boot_loader(char *which_device) {
    23172306    /*@ buffer ***************************************************** */
    23182307    char *list_drives_cmd = NULL;
     2308    char *tmp = NULL;
    23192309    char *current_drive;
    23202310
     
    23282318    /*@ end vars *************************************************** */
    23292319
    2330     malloc_string(current_drive);
    23312320
    23322321#ifdef __IA64__
     
    23342323    return ('E');
    23352324#endif
    2336     assert(which_device != NULL);
    2337 
    2338     mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
     2325
     2326    tmp = where_is_root_mounted();
     2327    mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp);
     2328    mr_free(tmp);
    23392329    log_it("list_drives_cmd = %s", list_drives_cmd);
    23402330
    2341     if (!(pdrives = popen(list_drives_cmd, "r"))) {
     2331    pdrives = popen(list_drives_cmd, "r");
     2332    mr_free(list_drives_cmd);
     2333
     2334    if (!pdrives) {
    23422335        log_OS_error("Unable to open list of drives");
    2343         mr_free(list_drives_cmd);
    2344         paranoid_free(current_drive);
    23452336        return ('\0');
    23462337    }
    2347     mr_free(list_drives_cmd);
    2348 
     2338
     2339    malloc_string(current_drive);
    23492340    for ((void)fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
    23502341         (void)fgets(current_drive, MAX_STR_LEN, pdrives)) {
     
    23532344        if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
    23542345            count_grubs++;
    2355             strcpy(which_device, current_drive);
     2346            mr_free(which_device);
     2347            mr_asprintf(which_device, "%s", current_drive);
    23562348            break;
    23572349        }
    23582350        if (does_string_exist_in_boot_block(current_drive, "LILO")) {
    23592351            count_lilos++;
    2360             strcpy(which_device, current_drive);
     2352            mr_free(which_device);
     2353            mr_asprintf(which_device, "%s", current_drive);
    23612354            break;
    23622355        }
     
    23952388            if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
    23962389                count_grubs++;
    2397                 strcpy(which_device, current_drive);
     2390                mr_free(which_device);
     2391                mr_asprintf(which_device, "%s", current_drive);
    23982392                break;
    23992393            }
    24002394            if (does_string_exist_in_boot_block(current_drive, "LILO")) {
    24012395                count_lilos++;
    2402                 strcpy(which_device, current_drive);
     2396                mr_free(which_device);
     2397                mr_asprintf(which_device, "%s", current_drive);
    24032398                break;
    24042399            }
     
    24612456char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
    24622457{
    2463     static char output[MAX_STR_LEN];
     2458    char *output;
    24642459    char *command = NULL;
    24652460    char *curr_fname;
     
    24712466    malloc_string(curr_fname);
    24722467    if (!does_file_exist(incoming)) {
    2473         log_it
    2474             ("resolve_softlinks_to_get_to_actual_device_file --- device not found");
    2475         strcpy(output, incoming);
     2468        log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found");
     2469        mr_asprintf(output, "%s", incoming);
    24762470    } else {
    24772471        strcpy(curr_fname, incoming);
     
    24822476            mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    24832477            mr_free(command);
    2484             for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
    2485                  p--);
     2478            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--);
    24862479            p++;
    24872480            mr_asprintf(scratch, "%s", p);
     
    25062499            lstat(curr_fname, &statbuf);
    25072500        }
    2508         strcpy(output, curr_fname);
     2501        mr_asprintf(output, "%s", curr_fname);
    25092502        log_it("resolved %s to %s", incoming, output);
    25102503    }
     
    25212514char *which_partition_format(const char *drive)
    25222515{
    2523     static char output[4];
     2516    char *output;
    25242517    char *tmp = NULL;
    25252518    char *command = NULL;
     
    25382531
    25392532    if (strstr(tmp, "GPT") == NULL) {
    2540         strcpy(output, "MBR");
     2533        mr_asprintf(output, "MBR");
    25412534    } else {
    2542         strcpy(output, "GPT");
     2535        mr_asprintf(output, "GPT");
    25432536    }
    25442537    mr_free(tmp);
  • branches/2.2.10/mondo/src/common/libmondo-mountlist.c

    r2324 r2330  
    430430        part_table_fmt = which_partition_format(drive);
    431431        /* no spare primary partitions to help accommodate the logical(s)? */
    432         if ((curr_part_no >= 5 && prev_part_no == 4)
    433             && (strcmp(part_table_fmt, "MBR") == 0)) {
     432        if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt, "MBR") == 0)) {
    434433            mr_asprintf(tmp, " Partition 4 of %s is occupied.", drive);
    435434            log_it(tmp);
     
    438437            res++;
    439438        }
     439        mr_free(part_table_fmt);
     440
    440441        /* does partition /dev/hdNX exist more than once in the mountlist? */
    441442        for (i = 0, mountpoint_copies = 0, device_copies = 0;
  • branches/2.2.10/mondo/src/mondorestore/mondo-prep.c

    r2325 r2330  
    16521652    /** pointers **********************************************************/
    16531653    char *p;
    1654     char *part_table_fmt;
     1654    char *part_table_fmt = NULL;
    16551655    FILE *fout;
    16561656
     
    16991699                    log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
    17001700                    mr_free(partition_name);
    1701                     paranoid_free(output);
     1701                    mr_free(output);
     1702                    mr_free(part_table_fmt);
    17021703                    return (1);
    17031704                } else {
     
    17111712        }
    17121713    }
     1714    mr_free(part_table_fmt);
     1715
    17131716    mr_strcat(output, "\n");    /*start block (ENTER for next free blk */
    17141717    if (partsize > 0) {
Note: See TracChangeset for help on using the changeset viewer.