From: Robert Luberda Date: Thu, 17 Mar 2011 23:19:30 +0100 Subject: 0028 Fix hardening warnings Fix warnings emitted when hardening options are enabled. --- buildhash.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/buildhash.c b/buildhash.c index d060dcc..988f29e 100644 --- a/buildhash.c +++ b/buildhash.c @@ -145,6 +145,10 @@ char Sfile[MAXPATHLEN]; /* Name of statistics file */ static int silent = 0; /* NZ to suppress count reports */ +#define fwrite(a,b,c,d) do { if (fwrite(a, b, c, d) != c ) { \ + fprintf(stderr, "frwite() failed"); \ + exit(1); }\ + } while (0) int main (argc, argv) int argc; char * argv[]; @@ -274,7 +278,7 @@ static void output () hashheader.stringsize = 0; hashheader.lstringsize = 0; hashheader.tblsize = hashsize; - (void) fwrite ((char *) &hashheader, sizeof hashheader, 1, houtfile); + fwrite ((char *) &hashheader, sizeof hashheader, 1, houtfile); strptr = 0; /* ** Put out the strings from the flags table. This code assumes that @@ -289,14 +293,14 @@ static void output () { if (fentry->stripl) { - (void) fwrite ((char *) fentry->strip, fentry->stripl + 1, + fwrite ((char *) fentry->strip, fentry->stripl + 1, sizeof (ichar_t), houtfile); fentry->strip = (ichar_t *) strptr; strptr += (fentry->stripl + 1) * sizeof (ichar_t); } if (fentry->affl) { - (void) fwrite ((char *) fentry->affix, fentry->affl + 1, + fwrite ((char *) fentry->affix, fentry->affl + 1, sizeof (ichar_t), houtfile); fentry->affix = (ichar_t *) strptr; strptr += (fentry->affl + 1) * sizeof (ichar_t); @@ -312,14 +316,14 @@ static void output () { if (fentry->stripl) { - (void) fwrite ((char *) fentry->strip, fentry->stripl + 1, + fwrite ((char *) fentry->strip, fentry->stripl + 1, sizeof (ichar_t), houtfile); fentry->strip = (ichar_t *) strptr; strptr += (fentry->stripl + 1) * sizeof (ichar_t); } if (fentry->affl) { - (void) fwrite ((char *) fentry->affix, fentry->affl + 1, + fwrite ((char *) fentry->affix, fentry->affl + 1, sizeof (ichar_t), houtfile); fentry->affix = (ichar_t *) strptr; strptr += (fentry->affl + 1) * sizeof (ichar_t); @@ -337,19 +341,19 @@ static void output () for (i = 0; i < hashheader.nstrchartype; i++) { n = strlen ((char *) chartypes[i].name) + 1; - (void) fwrite ((char *) chartypes[i].name, n, 1, houtfile); + fwrite ((char *) chartypes[i].name, n, 1, houtfile); strptr += n; n = strlen (chartypes[i].deformatter) + 1; - (void) fwrite (chartypes[i].deformatter, n, 1, houtfile); + fwrite (chartypes[i].deformatter, n, 1, houtfile); strptr += n; for (n = 0; chartypes[i].suffixes[n] != '\0'; n += strlen (&chartypes[i].suffixes[n]) + 1) ; n++; - (void) fwrite (chartypes[i].suffixes, n, 1, houtfile); + fwrite (chartypes[i].suffixes, n, 1, houtfile); strptr += n; - (void) fwrite (&chartypes[i].options, 1, 1, houtfile); + fwrite (&chartypes[i].options, 1, 1, houtfile); strptr++; } hashheader.lstringsize = strptr; @@ -369,7 +373,7 @@ static void output () else { n = strlen ((char *) dp->word) + 1; - (void) fwrite (dp->word, n, 1, houtfile); + fwrite (dp->word, n, 1, houtfile); dp->word = (unsigned char *) strptr; strptr += n; } @@ -397,23 +401,23 @@ static void output () dp->next = (struct dent *)-1; } #ifdef PIECEMEAL_HASH_WRITES - (void) fwrite ((char *) dp, sizeof (struct dent), 1, houtfile); + fwrite ((char *) dp, sizeof (struct dent), 1, houtfile); #endif /* PIECEMEAL_HASH_WRITES */ } #ifndef PIECEMEAL_HASH_WRITES - (void) fwrite ((char *) hashtbl, sizeof (struct dent), hashsize, houtfile); + fwrite ((char *) hashtbl, sizeof (struct dent), hashsize, houtfile); #endif /* PIECEMEAL_HASH_WRITES */ /* Put out the language tables */ - (void) fwrite ((char *) sflaglist, + fwrite ((char *) sflaglist, sizeof (struct flagent), numsflags, houtfile); hashheader.stblsize = numsflags; - (void) fwrite ((char *) pflaglist, + fwrite ((char *) pflaglist, sizeof (struct flagent), numpflags, houtfile); hashheader.ptblsize = numpflags; /* Finish filling in the hash header. */ hashheader.stringsize = strptr; rewind (houtfile); - (void) fwrite ((char *) &hashheader, sizeof hashheader, 1, houtfile); + fwrite ((char *) &hashheader, sizeof hashheader, 1, houtfile); (void) fclose (houtfile); }