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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.