Changeset 3777 in MondoRescue


Ignore:
Timestamp:
Nov 19, 2020, 2:17:57 AM (3 years ago)
Author:
Bruno Cornec
Message:

Fix some remaining memory allocation errors

Location:
branches/3.3/mondo
Files:
6 edited

Legend:

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

    r3746 r3777  
    487487        ntapedev = get_non_rewind_dev(bkpinfo->media_device);
    488488        if ((bkpinfo->use_obdr) && (ntapedev != NULL)) {
    489             strncpy(bkpinfo->media_device,ntapedev,(size_t)(MAX_STR_LEN / 4));
     489            strncpy(bkpinfo->media_device,ntapedev,(size_t)((MAX_STR_LEN / 4)-1));
    490490        } else {
    491491            if (ntapedev == NULL) {
  • branches/3.3/mondo/src/common/libmondo-cli.c

    r3658 r3777  
    466466        tmp2 = call_program_and_get_last_line_of_output(tmp1);
    467467        mr_free(tmp1);
    468         strncpy(bkpinfo->isodir, tmp2, MAX_STR_LEN / 4);
     468        strncpy(bkpinfo->isodir, tmp2, (MAX_STR_LEN / 4)-1);
    469469        mr_free(tmp2);
    470470
     
    514514                }
    515515                tmp2 = call_program_and_get_last_line_of_output(tmp1);
    516                 strncpy(bkpinfo->isodir, tmp2, MAX_STR_LEN / 4);
     516                strncpy(bkpinfo->isodir, tmp2,(MAX_STR_LEN / 4)-1);
    517517                mr_free(tmp2);
    518518                if (strlen(bkpinfo->isodir) < 3) {
     
    661661
    662662    if (flag_set['x']) {
    663         strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
     663        strncpy(bkpinfo->image_devs, flag_val['x'],(MAX_STR_LEN / 4)-1);
    664664        if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
    665665            fatal_error("Please install ntfsprogs package/tarball.");
     
    680680
    681681    if (flag_set['p']) {
    682         strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
     682        strncpy(bkpinfo->prefix, flag_val['p'],(MAX_STR_LEN / 4)-1);
    683683        log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
    684684    }
     
    686686    if (flag_set['d']) {        /* backup directory (if ISO/NETFS) */
    687687        if (flag_set['i']) {
    688             strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
     688            strncpy(bkpinfo->isodir, flag_val['d'],(MAX_STR_LEN / 4)-1);
    689689            sprintf(tmp, "ls -l %s", bkpinfo->isodir);
    690690            if (run_program_and_log_output(tmp, 2)) {
     
    695695            mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
    696696        } else {                /* backup device (if tape/CD-R/CD-RW) */
    697             strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
     697            strncpy(bkpinfo->media_device, flag_val['d'],(MAX_STR_LEN / 4)-1);
    698698        }
    699699    }
  • branches/3.3/mondo/src/common/libmondo-devices.c

    r3755 r3777  
    492492
    493493    if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
    494         if (!popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", dev, MAX_STR_LEN / 4)) {
     494        if (!popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", dev,(MAX_STR_LEN / 4)-1)) {
    495495            res = 1;
    496496        } else {
     
    23082308                log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
    23092309                mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
    2310                 if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN / 4)) {
     2310                if (!popup_and_get_string("Device?", comment, bkpinfo->media_device,(MAX_STR_LEN / 4)-1)) {
    23112311                    log_to_screen("User has chosen not to backup the machine");
    23122312                    finish(1);
     
    23312331            if (!bkpinfo->media_device[0]) {
    23322332                if (bkpinfo->backup_media_type == usb) {
    2333                     i = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device, MAX_STR_LEN / 4);
     2333                    i = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device, (MAX_STR_LEN / 4)-1);
    23342334                } else {
    23352335                    if (g_kernel_version < 2.6) {
    2336                         i = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device, MAX_STR_LEN / 4);
     2336                        i = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
    23372337                    } else {
    2338                         i = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device, MAX_STR_LEN / 4);
     2338                        i = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
    23392339                    }
    23402340                }
     
    23852385        }
    23862386        if (!bkpinfo->media_device[0]) {
    2387             if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device, MAX_STR_LEN / 4)) {
     2387            if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1)) {
    23882388                log_to_screen("User has chosen not to backup the machine");
    23892389                finish(1);
     
    24572457#endif
    24582458        {
    2459             if (!popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", p, MAX_STR_LEN / 4)) {
     2459            if (!popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", p,(MAX_STR_LEN / 4)-1)) {
    24602460                log_to_screen("User has chosen not to backup the machine");
    24612461                finish(1);
     
    25232523        }
    25242524        strcpy(tmp1, bkpinfo->netfs_proto);
    2525         if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) {
     2525        if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN-1)) {
    25262526            log_to_screen("User has chosen not to backup the machine");
    25272527            finish(1);
     
    25312531
    25322532        strcpy(tmp1, bkpinfo->netfs_mount);
    2533         if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN)) {
     2533        if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN-1)) {
    25342534            log_to_screen("User has chosen not to backup the machine");
    25352535            finish(1);
     
    25432543            strcpy(tmp1, "");
    25442544        }
    2545         if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1, MAX_STR_LEN)) {
     2545        if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1, MAX_STR_LEN-1)) {
    25462546            log_to_screen("User has chosen not to backup the machine");
    25472547            finish(1);
     
    25602560        } else {
    25612561            // Why netfsdir ?
    2562             sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
     2562            snprintf(bkpinfo->isodir, (MAX_STR_LEN / 4) -1, "%s/netfsdir", bkpinfo->tmpdir);
    25632563            mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
    25642564            run_program_and_log_output(command, 5);
     
    26062606        }
    26072607        strcpy(tmp1, bkpinfo->netfs_remote_dir);
    2608         if (!popup_and_get_string ("Directory", "Which directory within that mountpoint?", tmp1, MAX_STR_LEN)) {
     2608        if (!popup_and_get_string ("Directory", "Which directory within that mountpoint?", tmp1, MAX_STR_LEN-1)) {
    26092609            log_to_screen("User has chosen not to backup the machine");
    26102610            finish(1);
     
    26142614        bkpinfo->netfs_remote_dir = mr_strip_spaces(tmp1);
    26152615
    2616         if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix, MAX_STR_LEN / 4)) {
     2616        if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix,(MAX_STR_LEN / 4)-1)) {
    26172617            log_to_screen("User has chosen not to backup the machine");
    26182618            finish(1);
     
    26252625    case iso:
    26262626        if (!bkpinfo->disaster_recovery) {
    2627             if (!popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images.  Example: /mnt/raid0_0", bkpinfo->isodir, MAX_STR_LEN / 4)) {
     2627            if (!popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images.  Example: /mnt/raid0_0", bkpinfo->isodir,(MAX_STR_LEN / 4)-1)) {
    26282628                log_to_screen("User has chosen not to backup the machine");
    26292629                finish(1);
     
    26482648            }
    26492649        }
    2650         if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix, MAX_STR_LEN / 4)) {
     2650        if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix,(MAX_STR_LEN / 4)-1)) {
    26512651            log_to_screen("User has chosen not to backup the machine");
    26522652            finish(1);
     
    26722672
    26732673#ifdef __FreeBSD__
    2674             if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     2674            if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device,(MAX_STR_LEN / 4)-1)) {
    26752675                log_to_screen("User has chosen not to backup the machine");
    26762676                finish(1);
     
    26792679#else
    26802680            strcpy(tmp1, bkpinfo->boot_device);
    2681             if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", tmp1, MAX_STR_LEN / 4)) {
     2681            if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", tmp1,(MAX_STR_LEN / 4)-1)) {
    26822682                log_to_screen("User has chosen not to backup the machine");
    26832683                finish(1);
     
    27162716            strcpy(tmp1, "/");
    27172717        }
    2718         if (!popup_and_get_string("Backup paths", "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).", tmp1, MAX_STR_LEN)) {
     2718        if (!popup_and_get_string("Backup paths", "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).", tmp1, MAX_STR_LEN-1)) {
    27192719            log_to_screen("User has chosen not to backup the machine");
    27202720            finish(1);
     
    27292729// NTFS
    27302730        tmp = call_program_and_get_last_line_of_output("mr-parted2fdisk -l 2>/dev/null | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
    2731         strncpy(tmp1, tmp, MAX_STR_LEN / 4);
     2731        strncpy(tmp1, tmp,(MAX_STR_LEN / 4)-1);
    27322732        mr_free(tmp);
    27332733        if (strlen(tmp1) > 2) {
    2734             if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp1, MAX_STR_LEN / 4)) {
     2734            if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp1,(MAX_STR_LEN / 4)-1)) {
    27352735                log_to_screen("User has chosen not to backup the machine");
    27362736                finish(1);
    27372737            }
    2738             strncpy(bkpinfo->image_devs, tmp1, MAX_STR_LEN / 4);
     2738            strncpy(bkpinfo->image_devs, tmp1, (MAX_STR_LEN / 4)-1);
    27392739        }
    27402740
     
    27552755        mr_asprintf(oldtmp, "%s", bkpinfo->tmpdir);
    27562756        if (bkpinfo->tmpdir != NULL ) {
    2757             strncpy(p,bkpinfo->tmpdir,(16*MAX_STR_LEN)-1);
     2757            strncpy(p,bkpinfo->tmpdir,(MAX_STR_LEN / 4)-1);
    27582758        } else {
    27592759            p[0] = '\0';
     
    27712771        mr_asprintf(oldtmp, "%s", bkpinfo->scratchdir);
    27722772        if (bkpinfo->scratchdir != NULL ) {
    2773             strncpy(p,bkpinfo->scratchdir,(16*MAX_STR_LEN)-1);
     2773            strncpy(p,bkpinfo->scratchdir,(MAX_STR_LEN / 4)-1);
    27742774        } else {
    27752775            p[0] = '\0';
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.c

    r3753 r3777  
    927927    read_cfg_var(cfg_file, "iso-mnt", iso_mnt);
    928928    read_cfg_var(cfg_file, "iso-dir", iso_path);
    929     sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     929    snprintf(bkpinfo->isodir, (MAX_STR_LEN / 4)-1, "%s%s", iso_mnt, iso_path);
    930930    if (!bkpinfo->isodir[0]) {
    931931        strcpy(bkpinfo->isodir, old_isodir);
  • branches/3.3/mondo/test/test-mountlist.c

    r3566 r3777  
    3939
    4040char *g_mountlist_fname;
    41 char *g_mondo_home;
     41//char *g_mondo_home;
    4242
    43 char *g_getfacl;
    44 char *g_getfattr;
     43//char *g_getfacl;
     44//char *g_getfattr;
    4545
    4646extern char *MONDO_LOGFILE;
  • branches/3.3/mondo/test/test-truncname.c

    r3374 r3777  
    3333
    3434char *g_mountlist_fname;
    35 char *g_mondo_home;
     35//char *g_mondo_home;
    3636
    3737char *g_getfacl;
Note: See TracChangeset for help on using the changeset viewer.