Changeset 2209 in MondoRescue


Ignore:
Timestamp:
May 15, 2009, 4:56:31 AM (15 years ago)
Author:
Bruno Cornec
Message:
  • Use new libmr.a in build process
  • Use mr_strcat to fix a memory allocation bug when mountlist contains lots of references unavailable at restore time, creating a error when memory is statically allocated (more usage is expected now).
Location:
branches/2.2.9/mondo
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/configure.in

    r2202 r2209  
    125125AC_CHECK_FUNCS([bzero getcwd memmove memset mkdir mkfifo setenv strcasecmp strchr strerror strrchr strstr mkdtemp])
    126126
    127 AC_OUTPUT([Makefile src/Makefile src/common/Makefile src/mondoarchive/Makefile src/mondorestore/Makefile src/restore-scripts/Makefile src/restore-scripts/mondo/Makefile src/post-nuke.sample/Makefile src/post-nuke.sample/usr/Makefile src/post-nuke.sample/usr/bin/Makefile test/Makefile])
     127AC_OUTPUT([Makefile src/Makefile src/lib/Makefile src/common/Makefile src/mondoarchive/Makefile src/mondorestore/Makefile src/restore-scripts/Makefile src/restore-scripts/mondo/Makefile src/post-nuke.sample/Makefile src/post-nuke.sample/usr/Makefile src/post-nuke.sample/usr/bin/Makefile test/Makefile])
  • branches/2.2.9/mondo/src/Makefile.am

    r761 r2209  
    1 SUBDIRS        = common mondoarchive mondorestore restore-scripts post-nuke.sample
     1SUBDIRS        = lib common mondoarchive mondorestore restore-scripts post-nuke.sample
    22DIST_SUBDIRS   = ${SUBDIRS}
    33
  • branches/2.2.9/mondo/src/common/libmondo-mountlist.c

    r2207 r2209  
    1010
    1111#include "my-stuff.h"
    12 #include "mr_str.h"
     12#include "mr_mem.h"
    1313#include "mondostructures.h"
    1414#include "libmondo-mountlist.h"
     
    6262    char mountpoint[MAX_STR_LEN];
    6363
     64    char *flaws_str = NULL;
     65
    6466    /*@ long *********************************************************** */
    6567    long physical_drive_size = 0;
     
    7274    prev_part_no = 0;
    7375    tmp[0] = '\0';
     76    asprintf(&flaws_str, "%s", "");
    7477
    7578
     
    7881    if (physical_drive_size < 0) {
    7982        sprintf(tmp, " %s does not exist.", drive);
    80         asprintf(&flaws_str, "%s", tmp);
     83        mr_strcat(flaws_str, "%s", tmp);
    8184    } else {
    8285        sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     
    166169        if (((pos >= 0) || npos) && foundsome) {
    167170            mr_strcat(flaws_str, " %s has both DD and PC-style partitions.", drive);
    168             return ++res;       // fatal error
     171            return(flaws_str);      // fatal error
    169172        }
    170173
     
    177180                    sprintf(tmp, " Gap prior to %s.", device);
    178181                    log_it(tmp);
    179                     mr_strcat(flaws_str, tmp);
     182                    mr_strcat(flaws_str, "%s", tmp);
    180183                    res++;
    181184                } else if (curr_part_no > 5
     
    184187                            prev_part_no, curr_part_no);
    185188                    log_it(tmp);
    186                     mr_strcat(flaws_str, tmp);
     189                    mr_strcat(flaws_str, "%s", tmp);
    187190                    res++;
    188191                }
     
    195198                sprintf(tmp, " Partition %ss4 is occupied.", drive);
    196199                log_it(tmp);
    197                 mr_strcat(flaws_str, tmp);
     200                mr_strcat(flaws_str, "%s", tmp);
    198201                res++;
    199202            }
     
    208211                sprintf(tmp, " %s %s's.", number_to_text(device_copies),
    209212                        device);
    210                 if (!strstr(flaws_str, tmp)) {
     213                if (!strstr(flaws_str, "%s", tmp)) {
    211214                    log_it(tmp);
    212                     mr_strcat(flaws_str, tmp);
     215                    mr_strcat(flaws_str, "%s", tmp);
    213216                    res++;
    214217                }
     
    219222                sprintf(tmp, " %s is tiny!", device);
    220223                log_it(tmp);
    221                 mr_strcat(flaws_str, tmp);
     224                mr_strcat(flaws_str, "%s", tmp);
    222225                res++;
    223226            }
     
    231234                sprintf(tmp, " %s has a weird mountpoint.", device);
    232235                log_it(tmp);
    233                 mr_strcat(flaws_str, tmp);
     236                mr_strcat(flaws_str, "%s", tmp);
    234237                res++;
    235238            }
     
    238241                sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    239242                log_it(tmp);
    240                 mr_strcat(flaws_str, tmp);
     243                mr_strcat(flaws_str, "%s", tmp);
    241244                res++;
    242245            }
     
    254257                    sprintf(tmp, " Can only have up to 'h' in disklabel.");
    255258                    log_it(tmp);
    256                     mr_strcat(flaws_str, tmp);
     259                    mr_strcat(flaws_str, "%s", tmp);
    257260                    res++;
    258261                }
     
    269272                    if (!strstr(flaws_str, tmp)) {
    270273                        log_it(tmp);
    271                         mr_strcat(flaws_str, tmp);
     274                        mr_strcat(flaws_str, "%s", tmp);
    272275                        res++;
    273276                    }
     
    278281                    sprintf(tmp, " %s is tiny!", device);
    279282                    log_it(tmp);
    280                     mr_strcat(flaws_str, tmp);
     283                    mr_strcat(flaws_str, "%s", tmp);
    281284                    res++;
    282285                }
     
    290293                    sprintf(tmp, " %s has a weird mountpoint.", device);
    291294                    log_it(tmp);
    292                     mr_strcat(flaws_str, tmp);
     295                    mr_strcat(flaws_str, "%s", tmp);
    293296                    res++;
    294297                }
     
    298301                    sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    299302                    log_it(tmp);
    300                     mr_strcat(flaws_str, tmp);
     303                    mr_strcat(flaws_str, "%s", tmp);
    301304                    res++;
    302305                }
     
    317320                amount_allocated - physical_drive_size, drive);
    318321        log_it(tmp);
    319         mr_strcat(flaws_str, tmp);
     322        mr_strcat(flaws_str, "%s", tmp);
    320323        res++;
    321324    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     
    323326                physical_drive_size - amount_allocated, drive);
    324327        log_it(tmp);
    325         mr_strcat(flaws_str, tmp);
     328        mr_strcat(flaws_str, "%s", tmp);
    326329    }
    327330    if (res) {
    328         return (FALSE);
     331        return (NULL);
    329332    } else {
    330         return (TRUE);
     333        return (flaws_str);
    331334    }
    332335}
     
    348351    char *tmp;
    349352    char *device;
     353    char *flaws_str = NULL;
    350354
    351355    /*@ long *********************************************************** */
     
    359363    assert_string_is_neither_NULL_nor_zerolength(drive);
    360364    assert(mountlist != NULL);
    361     assert(flaws_str != NULL);
     365    asprintf(&flaws_str, "%s", "");
    362366
    363367    malloc_string(tmp);
    364368    malloc_string(device);
    365     flaws_str[0] = '\0';
    366369    prev_part_no = 0;
    367370    tmp[0] = '\0';
     
    372375    if (physical_drive_size < 0) {
    373376        sprintf(tmp, " %s does not exist.", drive);
    374         strcat(flaws_str, tmp);
     377        mr_strcat(flaws_str, "%s", tmp);
    375378        res++;
    376379        log_msg(1, tmp);
     
    392395                sprintf(tmp, " Gap prior to %s.", device);
    393396                log_it(tmp);
    394                 strcat(flaws_str, tmp);
     397                mr_strcat(flaws_str, "%s", tmp);
    395398                res++;
    396399            } else if (curr_part_no > 5
     
    399402                        prev_part_no, curr_part_no);
    400403                log_it(tmp);
    401                 strcat(flaws_str, tmp);
     404                mr_strcat(flaws_str, "%s", tmp);
    402405                res++;
    403406            }
     
    410413            sprintf(tmp, " Partition 4 of %s is occupied.", drive);
    411414            log_it(tmp);
    412             strcat(flaws_str, tmp);
     415            mr_strcat(flaws_str, "%s", tmp);
    413416            res++;
    414417        }
     
    425428            if (!strstr(flaws_str, tmp)) {
    426429                log_it(tmp);
    427                 strcat(flaws_str, tmp);
     430                mr_strcat(flaws_str, "%s", tmp);
    428431                res++;
    429432            }
     
    434437            sprintf(tmp, " %s is tiny!", device);
    435438            log_it(tmp);
    436             strcat(flaws_str, tmp);
     439            mr_strcat(flaws_str, "%s", tmp);
    437440            res++;
    438441        }
     
    445448            sprintf(tmp, " %s has a weird mountpoint.", device);
    446449            log_it(tmp);
    447             strcat(flaws_str, tmp);
     450            mr_strcat(flaws_str, "%s", tmp);
    448451            res++;
    449452        }
     
    452455            sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    453456            log_it(tmp);
    454             strcat(flaws_str, tmp);
     457            mr_strcat(flaws_str, "%s", tmp);
    455458            res++;
    456459        }
     
    465468                amount_allocated - physical_drive_size, drive);
    466469        log_it(tmp);
    467         strcat(flaws_str, tmp);
     470        mr_strcat(flaws_str, "%s", tmp);
    468471        res++;
    469472    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     
    471474                physical_drive_size - amount_allocated, drive);
    472475        log_it(tmp);
    473         strcat(flaws_str, tmp);
     476        mr_strcat(flaws_str, "%s", tmp);
    474477    }
    475478
     
    479482
    480483    if (res) {
    481         return (FALSE);
     484        return (NULL);
    482485    } else {
    483         return (TRUE);
     486        return (flaws_str);
    484487    }
    485488}
     
    514517
    515518    drivelist = malloc(sizeof(struct list_of_disks));
    516     malloc_string(flaws_str);
    517519    assert(mountlist != NULL);
    518520    assert(flaws_str_A != NULL);
    519521    assert(flaws_str_B != NULL);
    520522    assert(flaws_str_C != NULL);
    521     flaws_str[0] = '\0';
     523
     524    asprintf(&flaws_str, "%s", "");
    522525
    523526    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    540543        log_msg(8,"Entry: %d (%s)", i, drivelist->el[i].device);
    541544        log_msg(8,"Adding: %s to %s", tmp, flaws_str);
    542         strncat(flaws_str, tmp, MAX_STR_LEN -1);
     545        mr_strcat(flaws_str, "%s", tmp);
    543546        paranoid_free(tmp);
    544547    }
    545548    res += look_for_duplicate_mountpoints(mountlist, flaws_str);
    546     return (spread_flaws_across_three_lines
    547             (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
     549    res = spread_flaws_across_three_lines(flaws_str, flaws_str_A, flaws_str_B, flaws_str_C,res);
     550    paranoid_free(flaws_str);
     551    return(res);
    548552}
    549553
     
    584588 */
    585589int
    586 look_for_duplicate_mountpoints(struct mountlist_itself *mountlist,
    587                                char *flaws_str)
     590look_for_duplicate_mountpoints(struct mountlist_itself *mountlist, char *flaws_str)
    588591{
    589592
     
    617620            asprintf(&tmp, " %s %s's.", number_to_text(copies),
    618621                    curr_mountpoint);
    619             strcat(flaws_str, tmp);
     622            mr_strcat(flaws_str, "%s", tmp);
    620623            log_it(tmp);
    621624            paranoid_free(tmp);
  • branches/2.2.9/mondo/src/common/libmondo-string.c

    r2190 r2209  
    625625    assert(flaws_str != NULL);
    626626
    627     flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0';
    628 
    629 
    630627    if (!res && !strlen(flaws_str)) {
    631628        return (TRUE);
    632629    }
    633630    if (strlen(flaws_str) > 0) {
    634         sprintf(flaws_str_A, "%s", flaws_str + 1);
     631        paranoid_free(flaws_str_A);
     632        asprintf(&flaws_str_A, "%s", flaws_str + 1);
    635633    }
    636634    if (strlen(flaws_str_A) >= 74) {
    637635        for (i = 74; flaws_str_A[i] != ' '; i--);
    638         strcpy(flaws_str_B, flaws_str_A + i + 1);
     636        paranoid_free(flaws_str_B);
     637        asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1);
    639638        flaws_str_A[i] = '\0';
    640639    }
    641640    if (strlen(flaws_str_B) >= 74) {
    642641        for (i = 74; flaws_str_B[i] != ' '; i--);
    643         strcpy(flaws_str_C, flaws_str_B + i + 1);
     642        paranoid_free(flaws_str_C);
     643        asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1);
    644644        flaws_str_B[i] = '\0';
    645645    }
  • branches/2.2.9/mondo/src/lib/mr_msg.c

    r1226 r2209  
    4343    int res = 0;
    4444
    45     asprintf(&mr_logfile,logfile);
     45    if (asprintf(&mr_logfile, "%s", logfile) == -1) {
     46        fprintf(stderr,"Unable to alloc memory\n");
     47        fprintf(stderr,"Logging desactivated\n");
     48        mr_msg_close();
     49    }
    4650    if ((fout = fopen(mr_logfile, "w")) == NULL) {
    4751        fprintf(stderr,"Unable to write to %s\n",mr_logfile);
  • branches/2.2.9/mondo/src/mondorestore/Makefile.am

    r1930 r2209  
    1515mondorestore_SOURCES  = mondo-prep.c mondorestore.c mondo-rstr-newt.c \
    1616                        mondo-rstr-compare.c mondo-rstr-tools.c
    17 mondorestore_LDADD    = ${top_builddir}/src/common/libmondo.a @MONDORESTORE_STATIC@
     17mondorestore_LDADD    = ${top_builddir}/src/common/libmondo.a ${top_builddir}/src/lib/libmr.a @MONDORESTORE_STATIC@
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-newt.c

    r2140 r2209  
    19431943    /** buffers **********************************************************/
    19441944    char tmp[MAX_STR_LEN];
    1945     char flaws_str_A[MAX_STR_LEN];
    1946     char flaws_str_B[MAX_STR_LEN];
    1947     char flaws_str_C[MAX_STR_LEN];
     1945    char *flaws_str_A = NULL;
     1946    char *flaws_str_B = NULL;
     1947    char *flaws_str_C = NULL;
    19481948
    19491949    assert(mountlist != NULL);
    19501950    assert(raidlist != NULL);
    19511951
    1952     strcpy(flaws_str_A, "xxxxxxxxx");
    1953     strcpy(flaws_str_B, "xxxxxxxxx");
    1954     strcpy(flaws_str_C, "xxxxxxxxx");
     1952    asprintf(&flaws_str_A, "%s", "xxxxxxxxx");
     1953    asprintf(&flaws_str_B, "%s", "xxxxxxxxx");
     1954    asprintf(&flaws_str_C, "%s", "xxxxxxxxx");
    19551955    if (mountlist->entries > ARBITRARY_MAXIMUM) {
    19561956        log_to_screen("Arbitrary limits suck, man!");
     
    20432043        }
    20442044    }
     2045    paranoid_free(flaws_str_A);
     2046    paranoid_free(flaws_str_B);
     2047    paranoid_free(flaws_str_C);
    20452048    newtFormDestroy(myForm);
    20462049    newtPopWindow();
     
    20682071{
    20692072    int res = 0;
    2070 //  char tmp[MAX_STR_LEN];
    20712073
    20722074    iamhere("entering eml");
  • branches/2.2.9/mondo/src/mondorestore/mondorestore.c

    r2202 r2209  
    2323
    2424extern void twenty_seconds_til_yikes(void);
     25
     26/* We don't have a cleanup function yet */
     27void (*mr_cleanup)(void) = NULL;
    2528
    2629/* Reference to global bkpinfo */
     
    776779    bool boot_loader_installed = FALSE;
    777780  /** malloc **/
    778     char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
    779         tmpC[MAX_STR_LEN];
     781    char tmp[MAX_STR_LEN];
     782    char *tmpA;
     783    char *tmpB;
     784    char *tmpC;
    780785
    781786    assert(bkpinfo != NULL);
    782787    assert(mountlist != NULL);
    783788    assert(raidlist != NULL);
     789
     790    asprintf(&tmpA, "%s", "xxxxxxxxx");
     791    asprintf(&tmpB, "%s", "xxxxxxxxx");
     792    asprintf(&tmpC, "%s", "xxxxxxxxx");
    784793
    785794    log_msg(2, "nuke_mode --- starting");
  • branches/2.2.9/mondo/test/Makefile.am

    r2204 r2209  
    44sbin_PROGRAMS         = mrtest_mountlist
    55mrtest_mountlist_SOURCES  = test-mountlist.c ${top_builddir}/src/mondorestore/mondo-prep.c ${top_builddir}/src/mondorestore/mondo-rstr-newt.c ${top_builddir}/src/mondorestore/mondo-rstr-tools.c
    6 mrtest_mountlist_LDADD    = ${top_builddir}/src/common/libmondo.a @MONDORESTORE_STATIC@
     6mrtest_mountlist_LDADD    = ${top_builddir}/src/common/libmondo.a ${top_builddir}/src/lib/libmr.a @MONDORESTORE_STATIC@
  • branches/2.2.9/mondo/test/test-mountlist.c

    r2206 r2209  
    3535
    3636extern char *MONDO_LOGFILE;
    37 extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
    38                                  char direction);
     37extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction);
     38/* We don't have a cleanup function yet */
     39void (*mr_cleanup)(void) = NULL;
    3940
    4041void main() {
Note: See TracChangeset for help on using the changeset viewer.