Changeset 2214 in MondoRescue


Ignore:
Timestamp:
Jun 3, 2009, 7:10:28 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3094@localhost: bruno | 2009-06-03 17:25:25 +0200

Replaces strcpy in 5 source where no other impact by mr_asprintf. Improves quality report

Location:
branches/2.2.9/mondo
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/TODO

    r30 r2214  
     1NEW TODO
     2
     3list_of_NFS_devices_and_mounts  should allocate memory
     4
     5
    16MONDO TODO            Hugo Rabson <hugorabson@msn.com>              07/04/2004
    27
  • branches/2.2.9/mondo/src/common/libmondo-archive.c

    r2211 r2214  
    508508{
    509509    /*@ buffer ************************************************************ */
    510     char *tmp;
     510    char *tmp = NULL;
    511511    char *tmp1 = NULL;
    512512    char *tmp2 = NULL;
    513     char *scratchdir;
    514513    char *command = NULL;
    515     char *use_lzo_sz;
    516     char *use_gzip_sz;
    517     char *use_comp_sz;
    518     char *use_star_sz;
    519     char *bootldr_str;
    520     char *tape_device;
    521     char *last_filelist_number;
    522     char *broken_bios_sz;
    523     char *cd_recovery_sz;
    524     char *tape_size_sz;
    525     char *devs_to_exclude;
    526     char *use_lilo_sz;
    527     char *value;
    528     char *bootdev;
     514    char *use_lzo_sz = NULL;
     515    char *use_gzip_sz = NULL;
     516    char *use_comp_sz = NULL;
     517    char *use_star_sz = NULL;
     518    char *bootldr_str = NULL;
     519    char *tape_device = NULL;
     520    char *last_filelist_number = NULL;
     521    char *broken_bios_sz = NULL;
     522    char *cd_recovery_sz = NULL;
     523    char *tape_size_sz = NULL;
     524    char *devs_to_exclude = NULL;
     525    char *use_lilo_sz = NULL;   /* BCO: shared between LILO/ELILO */
     526    char *value = NULL;
     527    char *bootdev = NULL;
    529528    char *ntapedev = NULL;
    530529
     
    542541
    543542    assert(bkpinfo != NULL);
    544     tmp = malloc(9*MAX_STR_LEN);
    545     malloc_string(scratchdir);
    546     malloc_string(use_lzo_sz);
    547     malloc_string(use_gzip_sz);
    548     malloc_string(use_star_sz);
    549     malloc_string(use_comp_sz);
    550     malloc_string(bootldr_str);
    551     malloc_string(tape_device);
    552543    malloc_string(last_filelist_number);
    553     malloc_string(broken_bios_sz);
    554     malloc_string(cd_recovery_sz);
    555     malloc_string(tape_size_sz);
    556     malloc_string(devs_to_exclude);
    557     malloc_string(use_lilo_sz); /* BCO: shared between LILO/ELILO */
    558     malloc_string(value);
    559     malloc_string(bootdev);
    560 
    561     strcpy(scratchdir, bkpinfo->scratchdir);
    562     sprintf(tmp,
     544
     545    mr_asprintf(&tmp,
    563546            "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
    564547            bkpinfo->exclude_paths);
    565     strcpy(devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
    566     sprintf(tmp, "devs_to_exclude = '%s'", devs_to_exclude);
     548    mr_asprintf(&devs_to_exclude, "%s", call_program_and_get_last_line_of_output(tmp));
     549    mr_free(tmp);
     550
     551    mr_asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude);
    567552    log_msg(2, tmp);
     553    mr_free(tmp);
     554
    568555    mvaddstr_and_log_it(g_currentY, 0,
    569556                        "Calling MINDI to create boot+data disks");
    570     sprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir);
     557    mr_asprintf(&tmp, "%s/filelist.full", bkpinfo->tmpdir);
    571558    if (!does_file_exist(tmp)) {
    572         sprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
     559        mr_free(tmp);
     560        mr_asprintf(&tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
    573561        if (!does_file_exist(tmp)) {
    574562            fatal_error
     
    577565    }
    578566    lines_in_filelist = count_lines_in_file(tmp);
    579     sprintf(tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
    580     strcpy(last_filelist_number, last_line_of_file(tmp));
     567    mr_free(tmp);
     568
     569    mr_asprintf(&tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
     570    mr_asprintf(&last_filelist_number, "%s", last_line_of_file(tmp));
     571    mr_free(tmp);
     572
    581573    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    582         sprintf(tape_size_sz, "%ld", bkpinfo->media_size[1]);
     574        mr_asprintf(&tape_size_sz, "%ld", bkpinfo->media_size[1]);
    583575        ntapedev = get_non_rewind_dev(bkpinfo->media_device);
    584576        if ((bkpinfo->use_obdr) && (ntapedev != NULL)) {
     
    590582        }
    591583        paranoid_free(ntapedev);
    592         strcpy(tape_device, bkpinfo->media_device);
     584        mr_asprintf(&tape_device, "%s", bkpinfo->media_device);
    593585    } else {
    594         tape_size_sz[0] = '\0';
    595         tape_device[0] = '\0';
     586        mr_asprintf(&tape_size_sz, "%ld", 0L);;
     587        mr_asprintf(&tape_device, "");
    596588    }
    597589    if (bkpinfo->use_lzo) {
    598         strcpy(use_lzo_sz, "yes");
     590        mr_asprintf(&use_lzo_sz, "yes");
    599591    } else {
    600         strcpy(use_lzo_sz, "no");
     592        mr_asprintf(&use_lzo_sz, "no");
    601593    }
    602594    if (bkpinfo->use_gzip) {
    603         strcpy(use_gzip_sz, "yes");
     595        mr_asprintf(&use_gzip_sz, "yes");
    604596    } else {
    605         strcpy(use_gzip_sz, "no");
     597        mr_asprintf(&use_gzip_sz, "no");
    606598    }
    607599    if (bkpinfo->use_star) {
    608         strcpy(use_star_sz, "yes");
     600        mr_asprintf(&use_star_sz, "yes");
    609601    } else {
    610         strcpy(use_star_sz, "no");
     602        mr_asprintf(&use_star_sz, "no");
    611603    }
    612604
    613605    if (bkpinfo->compression_level > 0) {
    614         strcpy(use_comp_sz, "yes");
     606        mr_asprintf(&use_comp_sz, "yes");
    615607    } else {
    616         strcpy(use_comp_sz, "no");
    617     }
    618 
    619     strcpy(broken_bios_sz, "yes");  /* assume so */
     608        mr_asprintf(&use_comp_sz, "no");
     609    }
     610
     611    mr_asprintf(&broken_bios_sz, "yes");    /* assume so */
    620612    if (g_cd_recovery) {
    621         strcpy(cd_recovery_sz, "yes");
     613        mr_asprintf(&cd_recovery_sz, "yes");
    622614    } else {
    623         strcpy(cd_recovery_sz, "no");
     615        mr_asprintf(&cd_recovery_sz, "no");
    624616    }
    625617    if (bkpinfo->make_cd_use_lilo) {
    626         strcpy(use_lilo_sz, "yes");
     618        mr_asprintf(&use_lilo_sz, "yes");
    627619    } else {
    628         strcpy(use_lilo_sz, "no");
     620        mr_asprintf(&use_lilo_sz, "no");
    629621    }
    630622
     
    634626
    635627#ifdef __FreeBSD__
    636         strcpy(bootdev, call_program_and_get_last_line_of_output
     628        mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    637629               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    638630        if (!bootdev[0]) {
    639             strcpy(bootdev, call_program_and_get_last_line_of_output
     631            mr_free(bootdev);
     632            mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    640633                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    641634        }
     
    643636        /* Linux */
    644637#ifdef __IA64__
    645         strcpy(bootdev, call_program_and_get_last_line_of_output
     638        mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    646639               ("mount | grep ' /boot/efi ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    647640#else
    648         strcpy(bootdev, call_program_and_get_last_line_of_output
     641        mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    649642               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    650643#endif
    651644        if (strstr(bootdev, "/dev/cciss/")) {
     645            mr_free(bootdev);
    652646#ifdef __IA64__
    653             strcpy(bootdev, call_program_and_get_last_line_of_output
     647            mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    654648                   ("mount | grep ' /boot/efi ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    655649#else
    656             strcpy(bootdev, call_program_and_get_last_line_of_output
     650            mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    657651                   ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    658652#endif
    659653        }
    660654        if (!bootdev[0]) {
    661             strcpy(bootdev, call_program_and_get_last_line_of_output
     655            mr_free(bootdev);
     656            mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    662657                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    663658            if (strstr(bootdev, "/dev/cciss/")) {
    664                 strcpy(bootdev, call_program_and_get_last_line_of_output
     659                mr_free(bootdev);
     660                mr_asprintf(&bootdev, call_program_and_get_last_line_of_output
    665661                       ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    666662            }
     
    673669            ch = 'U';
    674670        if (bkpinfo->boot_loader != '\0') {
    675             sprintf(tmp, "User specified boot loader. It is '%c'.",
     671            mr_asprintf(&tmp, "User specified boot loader. It is '%c'.",
    676672                    bkpinfo->boot_loader);
    677673            log_msg(2, tmp);
     674            mr_free(tmp);
    678675        } else {
    679676            bkpinfo->boot_loader = ch;
    680677        }
    681678        if (bkpinfo->boot_device[0] != '\0') {
    682             sprintf(tmp, "User specified boot device. It is '%s'.",
     679            mr_asprintf(&tmp, "User specified boot device. It is '%s'.",
    683680                    bkpinfo->boot_device);
    684681            log_msg(2, tmp);
     682            mr_free(tmp);
    685683        } else {
    686684            strcpy(bkpinfo->boot_device, bootdev);
    687685        }
    688686    }
     687    mr_free(bootdev);
    689688
    690689    if (
     
    702701    }
    703702    if (bkpinfo->boot_loader == 'L') {
    704         strcpy(bootldr_str, "LILO");
     703        mr_asprintf(&bootldr_str, "LILO");
    705704        if (!does_file_exist("/etc/lilo.conf")) {
    706705            fatal_error
     
    708707        }
    709708    } else if (bkpinfo->boot_loader == 'G') {
    710         strcpy(bootldr_str, "GRUB");
     709        mr_asprintf(&bootldr_str, "GRUB");
    711710        if (!does_file_exist("/boot/grub/menu.lst")
    712711            && does_file_exist("/boot/grub/grub.conf")) {
     
    719718        }
    720719    } else if (bkpinfo->boot_loader == 'E') {
    721         strcpy(bootldr_str, "ELILO");
     720        mr_asprintf(&bootldr_str, "ELILO");
    722721        /* BCO: fix it for Debian, Mandrake, ... */
    723722        if (!does_file_exist("/etc/elilo.conf")
     
    750749        }
    751750    } else if (bkpinfo->boot_loader == 'R') {
    752         strcpy(bootldr_str, "RAW");
     751        mr_asprintf(&bootldr_str, "RAW");
    753752    }
    754753#ifdef __FreeBSD__
    755754    else if (bkpinfo->boot_loader == 'D') {
    756         strcpy(bootldr_str, "DD");
     755        mr_asprintf(&bootldr_str, "DD");
    757756    }
    758757
    759758    else if (bkpinfo->boot_loader == 'B') {
    760         strcpy(bootldr_str, "BOOT0");
     759        mr_asprintf(&bootldr_str, "BOOT0");
    761760    }
    762761#endif
    763762    else {
    764         strcpy(bootldr_str, "unknown");
    765     }
    766     sprintf(tmp, "Your boot loader is %s and it boots from %s",
     763        mr_asprintf(&bootldr_str, "unknown");
     764    }
     765    mr_asprintf(&tmp, "Your boot loader is %s and it boots from %s",
    767766            bootldr_str, bkpinfo->boot_device);
    768767    log_to_screen(tmp);
    769     sprintf(tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
     768    mr_free(tmp);
     769
     770    mr_asprintf(&tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
    770771    if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
    771772        log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
    772773    }
     774    mr_free(tmp);
     775
    773776    switch (bkpinfo->backup_media_type) {
    774777    case cdr:
    775         strcpy(value, "cdr");
     778        mr_asprintf(&value, "cdr");
    776779        break;
    777780    case cdrw:
    778         strcpy(value, "cdrw");
     781        mr_asprintf(&value, "cdrw");
    779782        break;
    780783    case cdstream:
    781         strcpy(value, "cdstream");
     784        mr_asprintf(&value, "cdstream");
    782785        break;
    783786    case tape:
    784         strcpy(value, "tape");
     787        mr_asprintf(&value, "tape");
    785788        break;
    786789    case udev:
    787         strcpy(value, "udev");
     790        mr_asprintf(&value, "udev");
    788791        break;
    789792    case iso:
    790         strcpy(value, "iso");
     793        mr_asprintf(&value, "iso");
    791794        break;
    792795    case nfs:
    793         strcpy(value, "nfs");
     796        mr_asprintf(&value, "nfs");
    794797        break;
    795798    case dvd:
    796         strcpy(value, "dvd");
     799        mr_asprintf(&value, "dvd");
    797800        break;
    798801    case usb:
    799         strcpy(value, "usb");
     802        mr_asprintf(&value, "usb");
    800803        break;
    801804    default:
     
    808811    }
    809812
    810     sprintf(tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
     813    mr_asprintf(&tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
    811814    if (write_one_liner_data_file(tmp, value)) {
    812815        res++;
     
    814817                __LINE__);
    815818    }
    816     sprintf(tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
     819    mr_free(value);
     820    mr_free(tmp);
     821
     822    mr_asprintf(&tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
    817823    if (write_one_liner_data_file(tmp, bootldr_str)) {
    818824        res++;
     
    820826                __LINE__);
    821827    }
    822     sprintf(tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
     828    mr_free(bootldr_str);
     829    mr_free(tmp);
     830
     831    mr_asprintf(&tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
    823832    if (bkpinfo->differential) {
    824833        res += write_one_liner_data_file(tmp, "1");
     
    826835        res += write_one_liner_data_file(tmp, "0");
    827836    }
     837    mr_free(tmp);
    828838
    829839    if (g_getfattr) {
     
    861871    }
    862872    paranoid_free(command);
    863     sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
    864             bkpinfo->kernel_path);
    865 
    866873    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
    867874
     
    892899            use_gzip_sz);       // parameter #20 (STRING)
    893900
     901    mr_free(devs_to_exclude);
     902    mr_free(last_filelist_number);
     903    mr_free(tape_device);
     904    mr_free(use_lzo_sz);
     905    mr_free(use_gzip_sz);
     906    mr_free(use_star_sz);
     907    mr_free(use_comp_sz);
     908    mr_free(broken_bios_sz);
     909    mr_free(cd_recovery_sz);
     910    mr_free(use_lilo_sz);
     911    mr_free(tape_size_sz);
     912
    894913    if (bkpinfo->nonbootable_backup) {
    895914        mr_strcat(command, " NONBOOTABLE");
     
    928947            paranoid_free(command);
    929948        } else {
    930             sprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
     949            mr_asprintf(&tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
    931950                bkpinfo->tmpdir);
    932951            if (system(tmp)) {
    933952                fatal_error("Cannot find all.tar.gz in tmpdir");
    934953            }
     954            mr_free(tmp);
    935955        }
    936956        if (res) {
     
    942962        log_to_screen("Mindi failed to create your boot+data disks.");
    943963        mr_asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
    944         strcpy(tmp, call_program_and_get_last_line_of_output(command));
     964        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    945965        paranoid_free(command);
    946966
     
    948968            popup_and_OK(tmp);
    949969        }
    950     }
    951     paranoid_free(tmp);
    952     paranoid_free(use_lzo_sz);
    953     paranoid_free(use_gzip_sz);
    954     paranoid_free(scratchdir);
    955     paranoid_free(use_comp_sz);
    956     paranoid_free(bootldr_str);
    957     paranoid_free(tape_device);
    958     paranoid_free(last_filelist_number);
    959     paranoid_free(broken_bios_sz);
    960     paranoid_free(cd_recovery_sz);
    961     paranoid_free(tape_size_sz);
    962     paranoid_free(devs_to_exclude);
    963     paranoid_free(use_lilo_sz);
    964     paranoid_free(value);
    965     paranoid_free(bootdev);
    966     paranoid_free(use_star_sz);
     970        mr_free(tmp);
     971    }
    967972    return (res);
    968973}
     
    13521357    char *storing_afioball_fname;
    13531358    char *tmp = NULL;
    1354     char *media_usage_comment;
     1359    char *media_usage_comment = NULL;
    13551360    pthread_t archival_thread[ARCH_THREADS];
    13561361    char *p_list_of_fileset_flags;
     
    13701375    malloc_string(curr_acl_list_fname);
    13711376    malloc_string(storing_filelist_fname);
    1372     malloc_string(media_usage_comment);
    13731377    malloc_string(storing_afioball_fname);
    13741378    transfer_block =
     
    14341438            misc_counter_that_is_not_important =
    14351439                (misc_counter_that_is_not_important + 1) % 5;
     1440            /* BCO the media_usage_comment is not really initialized there !
    14361441            if (!misc_counter_that_is_not_important) {
    14371442                update_progress_form(media_usage_comment);
     1443                */
    14381444            }
    14391445            sleep(1);
     
    14621468                sleep(5);
    14631469            }
    1464             strcpy(media_usage_comment, percent_media_full_comment());
     1470            mr_asprintf(&media_usage_comment, "%s", percent_media_full_comment());
    14651471            /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    14661472            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     
    15031509            g_current_progress++;
    15041510            update_progress_form(media_usage_comment);
     1511            mr_free(media_usage_comment);
    15051512            if (res) {
    15061513                mr_asprintf(&tmp,
     
    15371544    paranoid_free(result_str);
    15381545    paranoid_free(storing_filelist_fname);
    1539     paranoid_free(media_usage_comment);
    15401546    paranoid_free(storing_afioball_fname);
    15411547    paranoid_free(curr_xattr_list_fname);
     
    19801986bool is_dev_an_NTFS_dev(char *bigfile_fname)
    19811987{
    1982     char *tmp;
    1983     char *command;
    1984     malloc_string(tmp);
    1985     malloc_string(command);
    1986     sprintf(command,
     1988    char *tmp = NULL;
     1989    char *command = NULL;
     1990    bool ret = TRUE;
     1991
     1992    mr_asprintf(&command,
    19871993            "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
    19881994            bigfile_fname);
    19891995    log_msg(1, "command = '%s'", command);
    1990     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1996    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     1997    mr_free(command);
     1998
    19911999    log_msg(1, "--> tmp = '%s'", tmp);
    19922000    if (strstr(tmp, "NTFS")) {
    19932001        iamhere("TRUE");
    1994         return (TRUE);
     2002        ret = TRUE;
    19952003    } else {
    19962004        iamhere("FALSE");
    1997         return (FALSE);
    1998     }
     2005        ret = FALSE;
     2006    }
     2007    mr_free(tmp);
     2008    return(ret);
    19992009}
    20002010
     
    22032213    char *curr_acl_list_fname;
    22042214    char *tmp = NULL;
    2205     char *media_usage_comment;
     2215    char *media_usage_comment = NULL;
    22062216
    22072217    malloc_string(curr_afioball_fname);
    2208     malloc_string(media_usage_comment);
    22092218    malloc_string(curr_filelist_fname);
    22102219    malloc_string(curr_xattr_list_fname);
     
    22562265        }
    22572266
    2258         strcpy(media_usage_comment, percent_media_full_comment());
     2267        mr_asprintf(&media_usage_comment, "%s", percent_media_full_comment());
    22592268
    22602269        /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     
    22942303        g_current_progress++;
    22952304        update_progress_form(media_usage_comment);
     2305        mr_free(media_usage_comment);
    22962306
    22972307        if (res) {
     
    23152325    paranoid_free(curr_filelist_fname);
    23162326    paranoid_free(curr_afioball_fname);
    2317     paranoid_free(media_usage_comment);
    23182327    paranoid_free(curr_xattr_list_fname);
    23192328    paranoid_free(curr_acl_list_fname);
     
    25002509
    25012510    /*@ buffers ******************************************************** */
    2502     char *tmp, *curr_file, *cf;
     2511    char *tmp = NULL;
     2512    char *curr_file = NULL
     2513    char *cf;
    25032514
    25042515    /*@ long ************************************************************ */
     
    25072518
    25082519    assert(bkpinfo != NULL);
    2509     malloc_string(curr_file);
    2510     tmp = malloc(1200);
    25112520    would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
    25122521    va_start(ap, files_to_add); // initialize the variable arguments
     
    25152524            continue;
    25162525        }
    2517         strcpy(curr_file, cf);
     2526        mr_asprintf(&curr_file, cf);
    25182527        if (!does_file_exist(curr_file)) {
    25192528            log_msg(1,
     
    25242533            would_occupy += length_of_file(curr_file) / 1024;
    25252534        }
     2535        mr_free(curr_file);
    25262536    }
    25272537    va_end(ap);
     
    25432553            continue;
    25442554        }
    2545         strcpy(curr_file, cf);
    2546 
    2547         sprintf(tmp, "mv -f %s %s/archives/", curr_file,
    2548                 bkpinfo->scratchdir);
     2555        mr_asprintf(&curr_file, cf);
     2556
     2557        mr_asprintf(&tmp, "mv -f %s %s/archives/", curr_file, bkpinfo->scratchdir);
     2558        mr_free(curr_file);
    25492559        res = run_program_and_log_output(tmp, 5);
    25502560        retval += res;
     
    25542564            log_msg(8, "Moved %s to CD OK", tmp);
    25552565        }
    2556         //      unlink (curr_file);
     2566        mr_free(tmp);
    25572567    }
    25582568    va_end(ap);
     
    25622572                "Warning - errors occurred while I was adding files to CD dir");
    25632573    }
    2564     paranoid_free(tmp);
    2565     paranoid_free(curr_file);
    25662574    return (retval);
    25672575}
     
    26092617    char start_chr;
    26102618    char stop_chr;
    2611     char *curr_file, *cf;
     2619    char *curr_file = NULL
     2620    char *cf;
    26122621    /*@ long long ****************************************************** */
    26132622    off_t length_of_incoming_file = (off_t)0;
     
    26162625
    26172626    assert(bkpinfo != NULL);
    2618     malloc_string(curr_file);
    26192627    va_start(ap, files_to_add);
    26202628    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     
    26222630            continue;
    26232631        }
    2624         strcpy(curr_file, cf);
     2632        mr_asprintf(&curr_file, cf);
    26252633        if (!does_file_exist(curr_file)) {
    26262634            log_msg(1,
     
    26282636                    curr_file);
    26292637        }
    2630 /* create header chars */
     2638        /* create header chars */
    26312639        start_chr = BLK_START_AN_AFIO_OR_SLICE;
    26322640        stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
    2633 /* ask for new tape if necessary */
     2641        /* ask for new tape if necessary */
    26342642        length_of_incoming_file = length_of_file(curr_file);
    26352643        write_header_block_to_stream(length_of_incoming_file, curr_file,
     
    26452653        retval += res;
    26462654        unlink(curr_file);
    2647 /* write closing header */
     2655        mr_free(curr_file);
     2656        /* write closing header */
    26482657        write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
    26492658    }
     
    26542663                "Warning - errors occurred while I was adding file to tape");
    26552664    }
    2656     paranoid_free(curr_file);
    26572665    return (retval);
    26582666}
     
    26782686    char *tmp;
    26792687    int res = 0;
    2680     char *bkp;
     2688    char *bkp = NULL;
    26812689    char *cdrecord;
    26822690
    26832691    malloc_string(tmp);
    2684     malloc_string(bkp);
    26852692    malloc_string(cdrecord);
    2686     strcpy(bkp, cdrw_dev);
     2693    mr_asprintf(&bkp, cdrw_dev);
    26872694    if (find_cdrw_device(cdrw_dev)) {
    26882695        strcpy(cdrw_dev, bkp);
     
    27132720        }
    27142721    }
     2722    mr_free(bkp);
     2723
    27152724//  retract_CD_tray_and_defeat_autorun();
    27162725    paranoid_free(tmp);
    27172726    paranoid_free(cdrecord);
    2718     paranoid_free(bkp);
    27192727    return (res);
    27202728}
     
    27422750    char *cdrom_dev;
    27432751    char *cdrw_dev;
    2744     char *our_serial_str;
     2752    char *our_serial_str = NULL;
    27452753    bool ok_go_ahead_burn_it;
    27462754    int cd_number = -1;
     
    27582766    malloc_string(szcdno);
    27592767    malloc_string(szserfname);
    2760     malloc_string(our_serial_str);
    27612768    malloc_string(szunmount);
    27622769
     
    27852792        sprintf(szunmount, "umount %s", mtpt);
    27862793        cd_number = -1;
    2787         our_serial_str[0] = '\0';
    27882794        sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
     2795        mr_asprintf(&our_serial_str, "%s", "");
    27892796        if ((attempt_to_mount_returned_this =
    27902797             run_program_and_log_output(tmp, 1))) {
     
    28122819            cd_number = atoi(last_line_of_file(szcdno));
    28132820            sprintf(tmp, "cat %s 2> /dev/null", szserfname);
    2814             strcpy(our_serial_str,
     2821            mr_free(our_serial_str);
     2822            mr_asprintf(&our_serial_str, "%s",
    28152823                   call_program_and_get_last_line_of_output(tmp));
    28162824            // FIXME - should be able to use last_line_of_file(), surely?
     
    28362844            log_to_screen("...but not part of _our_ backup set.");
    28372845        }
     2846        mr_free(our_serial_str);
    28382847    } else {
    28392848        log_msg(2,
     
    28832892    paranoid_free(szcdno);
    28842893    paranoid_free(szserfname);
    2885     paranoid_free(our_serial_str);
    28862894    paranoid_free(szunmount);
    28872895    if (pmountable) {
     
    29662974    char *checksum_line, *command;
    29672975    char *tempblock;
    2968     char *curr_slice_fname_uncompressed;
    2969     char *curr_slice_fname_compressed;
    2970     char *file_to_archive;
     2976    char *curr_slice_fname_uncompressed = NULL;
     2977    char *curr_slice_fname_compressed = NULL;
     2978    char *file_to_archive = NULL;
    29712979    char *file_to_openin;
    29722980    /*@ pointers ************************************************** */
     
    29832991    long optimal_set_size;
    29842992    bool should_I_compress_slices;
    2985     char *suffix;               // for compressed slices
     2993    char *suffix = NULL;                // for compressed slices
    29862994
    29872995    /*@ long long ************************************************** */
     
    30013009    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    30023010    malloc_string(checksum_line);
    3003     malloc_string(curr_slice_fname_uncompressed);
    3004     malloc_string(curr_slice_fname_compressed);
    3005     malloc_string(file_to_archive);
    3006     malloc_string(suffix);
    30073011    command = malloc(MAX_STR_LEN * 8);
    30083012
     
    30153019    if (is_this_file_compressed(biggie_filename)
    30163020        || bkpinfo->compression_level == 0) {
    3017         suffix[0] = '\0';
     3021        mr_asprintf(&suffix, "%s", "");
    30183022        //      log_it("%s is indeed compressed :-)", filename);
    30193023        should_I_compress_slices = FALSE;
    30203024    } else {
    3021         strcpy(suffix, bkpinfo->zip_suffix);
     3025        mr_asprintf(&suffix, "%s", bkpinfo->zip_suffix);
    30223026        should_I_compress_slices = TRUE;
    30233027    }
     
    30503054        if (!(fin = popen(command, "r"))) {
    30513055            log_OS_error("Unable to popen-in command");
     3056            mr_free(suffix);
    30523057            return (1);
    30533058        }
     
    30723077        log_msg(1, "Unable to open and write to %s\n", tmp);
    30733078        paranoid_free(tmp);
    3074         paranoid_free(suffix);
     3079        mr_free(suffix);
    30753080        return (1);
    30763081    }
     
    30933098        paranoid_free(checksum_line);
    30943099        paranoid_free(command);
     3100        mr_free(suffix);
    30953101        return (1);
    30963102    }
     
    31063112    i = bkpinfo->optimal_set_size / 256;
    31073113    for (slice_num = 1; !finished; slice_num++) {
    3108         strcpy(curr_slice_fname_uncompressed,
     3114        mr_asprintf(&curr_slice_fname_uncompressed, "%s",
    31093115               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
    31103116                           ""));
    3111         strcpy(curr_slice_fname_compressed,
     3117        mr_asprintf(&curr_slice_fname_compressed, "%s",
    31123118               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
    31133119                           suffix));
     
    31193125        if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
    31203126            log_OS_error(curr_slice_fname_uncompressed);
     3127            mr_free(suffix);
    31213128            return (1);
    31223129        }
     
    31883195            paranoid_free(tmp);
    31893196
    3190             strcpy(file_to_archive, curr_slice_fname_compressed);
     3197            mr_asprintf(&file_to_archive, curr_slice_fname_compressed);
    31913198            g_current_progress++;
    31923199        } else {                /* if i==0 then ... */
    31933200
    31943201            finished = TRUE;
    3195             strcpy(file_to_archive, curr_slice_fname_uncompressed);
     3202            mr_asprintf(&file_to_archive, curr_slice_fname_uncompressed);
    31963203            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    31973204                break;
    31983205            }
    31993206        }
     3207        mr_free(curr_slice_fname_uncompressed);
     3208        mr_free(curr_slice_fname_compressed);
    32003209
    32013210        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     
    32083217            res = move_files_to_cd(file_to_archive, NULL);
    32093218        }
     3219        mr_free(file_to_archive);
     3220
    32103221        retval += res;
    32113222        if (res) {
     
    32193230        }
    32203231    }
     3232    mr_free(suffix);
    32213233    paranoid_fclose(fin);
    32223234    mr_asprintf(&tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
     
    32323244    paranoid_free(checksum_line);
    32333245    paranoid_free(command);
    3234     paranoid_free(curr_slice_fname_uncompressed);
    3235     paranoid_free(curr_slice_fname_compressed);
    3236     paranoid_free(file_to_archive);
    3237     paranoid_free(suffix);
    32383246    return (retval);
    32393247}
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2211 r2214  
    9898        flag_set[i] = FALSE;
    9999    }
    100     //  strcpy (bkpinfo->scratchdir, "/home");
    101100    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    102101        bkpinfo->media_size[j] = 650;
     
    669668
    670669    malloc_string(tmp);
    671     malloc_string(psz);
    672670
    673671    assert(bkpinfo != NULL);
     
    11241122    {
    11251123//      strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
    1126         strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
     1124        asprintf(&psz, "%s", list_of_NFS_mounts_only());
    11271125        if (bkpinfo->exclude_paths[0]) {
    11281126            strncat(bkpinfo->exclude_paths, " ", 4*MAX_STR_LEN);
    11291127        }
    11301128        strncat(bkpinfo->exclude_paths, psz, 4*MAX_STR_LEN);
     1129        mr_free(psz);
     1130
    11311131        log_msg(3, "-N means we're now excluding %s",
    11321132                bkpinfo->exclude_paths);
     
    11391139
    11401140    if (flag_set['b']) {
    1141         strcpy(psz, flag_val['b']);
     1141        mr_asprintf(&psz, flag_val['b']);
    11421142        log_msg(1, "psz = '%s'", psz);
    11431143        if (psz[strlen(psz) - 1] == 'k') {
     
    11471147            itbs = atol(psz);
    11481148        }
     1149        mr_free(psz);
    11491150        log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
    11501151        log_msg(1, "Internal tape block size is now %ld bytes", itbs);
     
    14211422
    14221423    paranoid_free(tmp);
    1423     paranoid_free(psz);
    14241424    return (retval);
    14251425}
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2211 r2214  
    107107bool am_I_in_disaster_recovery_mode(void)
    108108{
    109     char *tmp, *comment;
     109    char *tmp = NULL;
     110    char *comment;
    110111    bool is_this_a_ramdisk = FALSE;
    111112
    112     malloc_string(tmp);
    113113    malloc_string(comment);
    114     strcpy(tmp, where_is_root_mounted());
     114    mr_asprintf(&tmp, "%s", where_is_root_mounted());
    115115    sprintf(comment, "root is mounted at %s\n", tmp);
    116116    log_msg(0, comment);
     
    133133    }
    134134#endif
     135    mr_free(tmp);
    135136
    136137    if (is_this_a_ramdisk) {
     
    144145        is_this_a_ramdisk = TRUE;
    145146    }
    146     paranoid_free(tmp);
    147147    paranoid_free(comment);
    148148    log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
     
    513513    /*@ buffers ************************ */
    514514    char *comment;
    515     char *tmp;
    516     char *cdr_exe;
     515    char *tmp = NULL;
     516    char *cdr_exe = NULL;
    517517    char *command;
    518518
    519519    malloc_string(comment);
    520     malloc_string(tmp);
    521     malloc_string(cdr_exe);
    522520    malloc_string(command);
    523521    if (g_cdrw_drive_is_here[0]) {
     
    525523        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    526524        paranoid_free(comment);
    527         paranoid_free(tmp);
    528         paranoid_free(cdr_exe);
    529525        paranoid_free(command);
    530526        return (0);
     
    534530                "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    535531        paranoid_free(comment);
    536         paranoid_free(tmp);
    537         paranoid_free(cdr_exe);
    538532        paranoid_free(command);
    539533        return (1);
     
    541535    run_program_and_log_output("insmod ide-scsi", -1);
    542536    if (find_home_of_exe("cdrecord")) {
    543         strcpy(cdr_exe, "cdrecord");
     537        mr_asprintf(&cdr_exe, "cdrecord");
    544538    } else {
    545         strcpy(cdr_exe, "dvdrecord");
    546     }
    547     tmp[0] = '\0';
     539        mr_asprintf(&cdr_exe, "dvdrecord");
     540    }
    548541    if (find_home_of_exe(cdr_exe)) {
    549542        sprintf(command,
    550543                "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1",
    551544                cdr_exe);
    552         strcpy(tmp, call_program_and_get_last_line_of_output(command));
    553     }
    554     if (strlen(tmp) < 2) {
     545        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     546    }
     547    if ((tmp == NULL) || (strlen(tmp) < 2)) {
    555548        paranoid_free(comment);
    556         paranoid_free(tmp);
    557         paranoid_free(cdr_exe);
     549        mr_free(tmp);
     550        mr_free(cdr_exe);
    558551        paranoid_free(command);
    559552        return 1;
     
    564557        strcpy(g_cdrw_drive_is_here, cdrw_device);
    565558        paranoid_free(comment);
    566         paranoid_free(tmp);
    567         paranoid_free(cdr_exe);
     559        mr_free(tmp);
     560        mr_free(cdr_exe);
    568561        paranoid_free(command);
    569562        return (0);
     
    597590    /*@ buffers ***************************************************** */
    598591    char *tmp;
    599     char *cdr_exe;
     592    char *tmp1 = NULL;
     593    char *cdr_exe = NULL;
    600594    char *phrase_one;
    601595    char *phrase_two;
     
    607601    /*@ intialize *************************************************** */
    608602    malloc_string(tmp);
    609     malloc_string(cdr_exe);
    610603    malloc_string(phrase_one);
    611604    malloc_string(phrase_two);
     
    640633
    641634    if (find_home_of_exe("cdrecord")) {
    642         strcpy(cdr_exe, "cdrecord");
     635        mr_asprintf(&cdr_exe, "cdrecord");
    643636    } else {
    644         strcpy(cdr_exe, "dvdrecord");
     637        mr_asprintf(&cdr_exe, "dvdrecord");
    645638    }
    646639    tmp[0] = '\0';
     
    663656        log_msg(4, "command=%s", command);
    664657        log_OS_error("Cannot popen command");
     658        mr_free(cdr_exe);
    665659        return (1);
    666660    }
     
    862856            cdr_exe, g_cdrw_drive_is_here);
    863857    log_msg(1, "command=%s", command);
    864     strcpy(tmp, call_program_and_get_last_line_of_output(command));
    865     if (tmp[0]) {
    866         strcpy(output, tmp);
     858    mr_asprintf(&tmp1, "%s", call_program_and_get_last_line_of_output(command));
     859    if (strlen(tmp1) > 0) {
     860        strcpy(output, tmp1);
    867861        log_msg(4, "Finally found it at %s", output);
    868862        retval = 0;
    869         goto end_of_find_cdrom_device;
    870863    } else {
    871864        log_msg(4, "Still couldn't find it.");
    872865        retval = 1;
    873         goto end_of_find_cdrom_device;
    874     }
     866    }
     867    mr_free(tmp1);
     868
    875869  end_of_find_cdrom_device:
    876870    paranoid_free(tmp);
    877     paranoid_free(cdr_exe);
     871    mr_free(cdr_exe);
    878872    paranoid_free(phrase_one);
    879873    paranoid_free(phrase_two);
     
    11031097    /*@ buffers ***************************************************** */
    11041098    char *incoming;
    1105     char *device_with_tab;
    1106     char *device_with_space;
    1107     char *tmp;
    1108     int retval = 0;
     1099    char *device_with_tab = NULL;
     1100    char *device_with_space = NULL;
     1101    char *tmp = NULL;
     1102    bool retval = FALSE;
    11091103
    11101104#ifdef __FreeBSD__
     
    11171111
    11181112    malloc_string(incoming);
    1119     malloc_string(device_with_tab);
    1120     malloc_string(device_with_space);
    1121     malloc_string(tmp);
    11221113    assert(device_raw != NULL);
    11231114//  assert_string_is_neither_NULL_nor_zerolength(device_raw);
     
    11251116        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
    11261117                device_raw);
    1127         sprintf(tmp, "/%s", device_raw);
     1118        mr_asprintf(&tmp, "/%s", device_raw);
    11281119    } else {
    1129         strcpy(tmp, device_raw);
     1120        mr_asprintf(&tmp, "%s", device_raw);
    11301121    }
    11311122    log_msg(1, "Is %s mounted?", tmp);
     
    11331124        log_msg(1,
    11341125                "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
    1135         return (0);
    1136     }
    1137     sprintf(device_with_tab, "%s\t", tmp);
    1138     sprintf(device_with_space, "%s ", tmp);
     1126        mr_free(tmp);
     1127        return(FALSE);
     1128    }
     1129    mr_asprintf(&device_with_tab, "%s\t", tmp);
     1130    mr_asprintf(&device_with_space, "%s ", tmp);
     1131    mr_free(tmp);
    11391132
    11401133    if (!(fin = popen("mount", "r"))) {
    11411134        log_OS_error("Cannot popen 'mount'");
    1142         return (FALSE);
     1135        return(FALSE);
    11431136    }
    11441137    for ((void)fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     
    11481141        {
    11491142            paranoid_pclose(fin);
    1150             retval = 1;
    1151             goto end_of_func;
    1152         }
    1153     }
     1143            paranoid_free(incoming);
     1144            return(TRUE);
     1145        }
     1146    }
     1147    mr_free(device_with_tab);
     1148    mr_free(device_with_space);
    11541149    paranoid_pclose(fin);
    1155     sprintf(tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null",
     1150    mr_asprintf(&tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null",
    11561151            SWAPLIST_COMMAND, device_with_space);
    11571152    log_msg(4, "tmp (command) = '%s'", tmp);
    11581153    if (!system(tmp)) {
    1159         retval = 1;
    1160         goto end_of_func;
    1161     }
    1162   end_of_func:
     1154        retval = TRUE;
     1155    }
     1156    mr_free(tmp);
    11631157    paranoid_free(incoming);
    1164     paranoid_free(device_with_tab);
    1165     paranoid_free(device_with_space);
    1166     paranoid_free(tmp);
    1167     return (retval);
     1158    return(retval);
    11681159}
    11691160
     
    12451236    /*@ buffer ****************************************************** */
    12461237    char *command;
    1247     char *dev;
    12481238    int retval;
    12491239
    12501240    malloc_string(command);
    1251     malloc_string(dev);
    12521241    assert_string_is_neither_NULL_nor_zerolength(device);
    12531242    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     
    12561245    if (isdigit(device[0])) {
    12571246        return(1);
    1258     } else {
    1259         strcpy(dev, device);
    12601247    }
    12611248    log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device,
     
    12761263
    12771264    paranoid_free(command);
    1278     paranoid_free(dev);
    12791265    return (retval);
    12801266}
     
    14821468// archiving_to_media is FALSE if I'm being called by mondorestore
    14831469{
    1484     char *tmp;
     1470    char *tmp = NULL;
    14851471    char *tmp1 = NULL;
    14861472    char *sz_size;
     
    14911477    FILE *fin;
    14921478
    1493     malloc_string(tmp);
    14941479    malloc_string(sz_size);
    14951480    malloc_string(command);
     
    15531538            if (bkpinfo->backup_media_type == dvd) {
    15541539                find_dvd_device(bkpinfo->media_device, FALSE);
    1555                 strcpy(tmp, "1");
     1540                mr_asprintf(&tmp, "1");
    15561541                sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    15571542                log_msg(1, "Setting to DVD defaults");
    15581543            } else {
    15591544                strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    1560                 strcpy(tmp, "4");
     1545                mr_asprintf(&tmp, "4");
    15611546                strcpy(sz_size, "650");
    15621547                log_msg(1, "Setting to CD defaults");
     
    15691554            }
    15701555            bkpinfo->cdrw_speed = atoi(tmp);    // if DVD then this shouldn't ever be used anyway :)
     1556            mr_free(tmp);
     1557
    15711558            sprintf(comment,
    15721559                    "How much data (in Megabytes) will each %s store?",
     
    16201607            if (bkpinfo->media_device[0]) {
    16211608                if (bkpinfo->backup_media_type == usb) {
    1622                     sprintf(tmp,
     1609                    mr_asprintf(&tmp,
    16231610                        "I think your %s media corresponds to %s. Is this correct?",
    16241611                        media_descriptor_string(bkpinfo->backup_media_type),
    16251612                        bkpinfo->media_device);
    16261613                } else {
    1627                     sprintf(tmp,
     1614                    mr_asprintf(&tmp,
    16281615                        "I think I've found your %s burner at SCSI node %s. Is this correct? (Say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details.)",
    16291616                        media_descriptor_string(bkpinfo->backup_media_type),
     
    16331620                    bkpinfo->media_device[0] = '\0';
    16341621                }
     1622                mr_free(tmp);
    16351623            }
    16361624            if (!bkpinfo->media_device[0]) {
     
    16911679                }
    16921680            }
    1693             sprintf(tmp,
    1694                     "I think I've found your tape streamer at %s; am I right on the money?",
    1695                     bkpinfo->media_device);
    16961681        }
    16971682        if (bkpinfo->media_device[0]) {
    1698             sprintf(tmp,
     1683            mr_asprintf(&tmp,
    16991684                    "I think I've found your tape streamer at %s; am I right on the money?",
    17001685                    bkpinfo->media_device);
     
    17021687                bkpinfo->media_device[0] = '\0';
    17031688            }
     1689            mr_free(tmp);
    17041690        }
    17051691        if (!bkpinfo->media_device[0]) {
     
    17121698            }
    17131699        }
    1714         sprintf(tmp, "ls -l %s", bkpinfo->media_device);
     1700        mr_asprintf(&tmp, "ls -l %s", bkpinfo->media_device);
    17151701        if (run_program_and_log_output(tmp, FALSE)) {
    17161702            log_to_screen("User has not specified a valid /dev entry");
    17171703            finish(1);
    17181704        }
     1705        mr_free(tmp);
    17191706        log_msg(4, "sz_size = %s", sz_size);
    17201707        sz_size[0] = '\0';
    1721 /*
    1722     if ((size_sz[0]=='\0' || atol(size_sz)==0) && archiving_to_media)
    1723       {
    1724         if (!popup_and_get_string("Tape size", "How much COMPRESSED data will one of your tape cartridges hold? (e.g. 4GB for 4 gigabytes)", size_sz, 16))
    1725           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1726       }
    1727 */
     1708
    17281709        bkpinfo->use_obdr = ask_me_yes_or_no
    17291710            ("Do you want to activate OBDR support for your tapes ?");
     
    18291810            sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    18301811            run_program_and_log_output(command, 5);
    1831             sprintf(tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount,
     1812            mr_asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount,
    18321813                    bkpinfo->isodir);
    18331814            run_program_and_log_output(tmp, 3);
     1815            mr_free(tmp);
     1816
    18341817            malloc_string(g_selfmounted_isodir);
    18351818            strcpy(g_selfmounted_isodir, bkpinfo->isodir);
     
    18401823            finish(1);
    18411824        }
    1842         strcpy(tmp, bkpinfo->nfs_remote_dir);
     1825        mr_asprintf(&tmp, bkpinfo->nfs_remote_dir);
    18431826        if (!popup_and_get_string
    18441827            ("Directory", "Which directory within that mountpoint?", tmp,
     
    18481831        }
    18491832        strcpy(bkpinfo->nfs_remote_dir, tmp);
     1833        mr_free(tmp);
     1834
    18501835        // check whether writable - we better remove surrounding spaces for this
    18511836        strip_spaces(bkpinfo->nfs_remote_dir);
     
    19811966            finish(1);
    19821967        }
    1983         strcpy(tmp, list_of_NFS_mounts_only());
     1968        mr_asprintf(&tmp, "%s", list_of_NFS_mounts_only());
    19841969        if (strlen(tmp) > 2) {
    19851970            if (bkpinfo->exclude_paths[0]) {
     
    19881973            strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
    19891974        }
     1975        mr_free(tmp);
    19901976// NTFS
    1991         strcpy(tmp,
     1977        mr_asprintf(&tmp, "%s",
    19921978               call_program_and_get_last_line_of_output
    19931979               ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     
    20021988            strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4);
    20031989        }
     1990        mr_free(tmp);
    20041991
    20051992
     
    20472034#else
    20482035    if (bkpinfo->backup_media_type == nfs) {
    2049         sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3",
    2050                 bkpinfo->nfs_mount);
    2051 //      strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp));
    20522036        log_msg(3, "I think the NFS mount is mounted at %s",
    20532037                bkpinfo->isodir);
     
    20782062        }
    20792063    }
    2080     paranoid_free(tmp);
    20812064    paranoid_free(sz_size);
    20822065    paranoid_free(command);
     
    21002083char *list_of_NFS_devices_and_mounts(void)
    21012084{
    2102     char *exclude_these_devices;
    2103     char *exclude_these_directories;
     2085    char *exclude_these_devices = NULL;
     2086    char *exclude_these_directories = NULL;
    21042087    static char result_sz[1024];
    21052088
    2106     malloc_string(exclude_these_devices);
    2107     malloc_string(exclude_these_directories);
    2108     strcpy(exclude_these_directories,list_of_NFS_mounts_only());
    2109     strcpy(exclude_these_devices,
     2089    mr_asprintf(exclude_these_directories,"%s",list_of_NFS_mounts_only());
     2090    mr_asprintf(exclude_these_devices,"%s",
    21102091           call_program_and_get_last_line_of_output
    21112092           ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2112     sprintf(result_sz, "%s %s", exclude_these_directories,
    2113             exclude_these_devices);
    2114     paranoid_free(exclude_these_devices);
    2115     paranoid_free(exclude_these_directories);
     2093    snprintf(result_sz, "%s %s", exclude_these_directories,
     2094            exclude_these_devices, 1023);
     2095    mr_free(exclude_these_devices);
     2096    mr_free(exclude_these_directories);
    21162097    return (result_sz);
    21172098}
     
    21282109char *list_of_NFS_mounts_only(void)
    21292110{
    2130     char *exclude_these_directories;
     2111    char *exclude_these_directories = NULL;
    21312112    static char result_sz[512];
    21322113
    2133     malloc_string(exclude_these_directories);
    2134     strcpy(exclude_these_directories,
     2114    mr_asprintf(&exclude_these_directories,"%s",
    21352115           call_program_and_get_last_line_of_output
    21362116           ("mount -t coda,ncpfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2137     sprintf(result_sz, "%s", exclude_these_directories);
    2138     paranoid_free(exclude_these_directories);
     2117    snprintf(result_sz, "%s", exclude_these_directories, 511);
     2118    mr_free(exclude_these_directories);
    21392119    return (result_sz);
    21402120}
     
    21832163{
    21842164    char *tmp = NULL;
    2185     char *command, *sz;
    2186 
    2187     malloc_string(command);
    2188     malloc_string(sz);
     2165    char *command = NULL;
     2166    char *sz = NULL;
     2167
    21892168    assert(bkpinfo != NULL);
    21902169
     
    22002179
    22012180    if (tmp[0] != '/') {
    2202         strcpy(sz, tmp);
     2181        mr_asprintf(&sz, tmp);
    22032182        paranoid_free(tmp);
    22042183        mr_asprintf(&tmp, "/%s", sz);
     2184        mr_free(sz);
    22052185    }
    22062186    if (!tmp[0]) {
     
    22142194    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    22152195
    2216     sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2196    mr_asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
    22172197    paranoid_free(tmp);
    22182198
    22192199    paranoid_system(command);
    2220     paranoid_free(command);
    2221     paranoid_free(sz);
     2200    mr_free(command);
    22222201}
    22232202
     
    25592538    char *command;
    25602539    char *curr_fname;
    2561     char *scratch;
    2562     char *tmp;
     2540    char *scratch = NULL;
     2541    char *tmp = NULL;
    25632542    char *p;
    25642543
    25652544    struct stat statbuf;
    25662545    command = malloc(1000);
    2567     malloc_string(tmp);
    2568     malloc_string(scratch);
    25692546    malloc_string(curr_fname);
    25702547    if (!does_file_exist(incoming)) {
     
    25782555            log_msg(1, "curr_fname = %s", curr_fname);
    25792556            sprintf(command, "file %s", curr_fname);
    2580             strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2557            mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
    25812558            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
    25822559                 p--);
    25832560            p++;
    2584             strcpy(scratch, p);
     2561            mr_asprintf(&scratch, p);
    25852562            for (p = scratch; *p != '\0' && *p != '\''; p++);
    25862563            *p = '\0';
    2587             log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp,
    2588                     scratch);
     2564            log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
     2565            mr_free(tmp);
     2566
    25892567            if (scratch[0] == '/') {
    25902568                strcpy(curr_fname, scratch);    // copy whole thing because it's an absolute softlink
     
    25992577                strcpy(p, scratch);
    26002578            }
     2579            mr_free(scratch);
    26012580            lstat(curr_fname, &statbuf);
    26022581        }
     
    26062585    paranoid_free(command);
    26072586    paranoid_free(curr_fname);
    2608     paranoid_free(tmp);
    26092587    return (output);
    26102588}
     
    26192597{
    26202598    static char output[4];
    2621     char *tmp;
     2599    char *tmp = NULL;
    26222600    char *command;
    26232601    char *fdisk;
     
    26252603    struct stat buf;
    26262604#endif
    2627     malloc_string(tmp);
    26282605    malloc_string(command);
    26292606    malloc_string(fdisk);
     
    26322609    log_msg(1, "Using %s", fdisk);
    26332610    sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
    2634     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2611    mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
    26352612    if (strstr(tmp, "GPT") == NULL) {
    26362613        strcpy(output, "MBR");
     
    26382615        strcpy(output, "GPT");
    26392616    }
     2617    mr_free(tmp);
     2618
    26402619    log_msg(0, "Found %s partition table format type", output);
    26412620    paranoid_free(command);
    2642     paranoid_free(tmp);
    26432621    paranoid_free(fdisk);
    26442622    return (output);
  • branches/2.2.9/mondo/src/common/libmondo-fifo.c

    r2049 r2214  
    155155void kill_buffer()
    156156{
    157     char *tmp;
    158     char *command;
     157    char *tmp = NULL;
     158    char *command = NULL;
    159159
    160160    if (g_sz_call_to_buffer == NULL) {
     
    164164        return;
    165165    }
    166     malloc_string(tmp);
    167     malloc_string(command);
    168166    paranoid_system("sync");
    169     sprintf(command,
     167    mr_asprintf(&command,
    170168            "ps %s | grep -F \"%s\" | grep -Fv grep | awk '{print $2;}' | grep -v PID | head -1", ps_options, g_sz_call_to_buffer);
    171169    log_msg(2, "kill_buffer() --- command = %s", command);
    172     strcpy(tmp, call_program_and_get_last_line_of_output(command));
    173     sprintf(command, "kill %s", tmp);
     170    mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     171    mr_free(command);
     172
     173    mr_asprintf(&command, "kill %s", tmp);
    174174    log_msg(2, "kill_buffer() --- command = %s", command);
    175175    if (strlen(tmp) > 0) {
    176176        run_program_and_log_output(command, TRUE);
    177177    }
    178     paranoid_free(tmp);
    179     paranoid_free(command);
     178    mr_free(tmp);
     179    mr_free(command);
    180180}
    181181
Note: See TracChangeset for help on using the changeset viewer.