--- pad.c.orig Sun Jul 23 09:14:10 2000 +++ pad.c Wed Oct 15 06:43:08 2003 @@ -31,17 +31,17 @@ #include "pad.h" #include "md5.h" -int main(argc, argv) - int argc; - char **argv; -{ - char *ifname[256], *ofname[256]; /* Names of files */ - FILE *ifp[256], *ofp[256]; /* file pointers themselves */ +int main (int argc, char *argv[]) { + + char *ifname[256]; /* array of input file names */ + char *ofname[256][FILENAME_MAX]; /* array of temp. output file names */ + FILE *ifp[256]; + int ofp[256]; struct md5_ctx context[256]; /* md5 contexts */ unsigned char digest[256][16]; /* md5 digests */ unsigned char currentbyte, readbyte; /* just a place to put new bytes */ char *outputname=NULL; /* output file name */ - char buf[256]; /* temporary string space */ + char buf[FILENAME_MAX]; /* temporary string space */ int defined_output=0, lastout, rands=-1, i, j; /* misc ints */ unsigned long bytecount=0, bytelimit=0; /* to limit/expand the filesize */ @@ -151,42 +151,42 @@ { if ((j != filesize(ifp[i])) && (i != 0)) { - fprintf(stderr, "Warning: Input files sizes differ. Output will match the size of the smallest input.\n"); + fprintf(stderr, "Warning: sizes of input files differ. Unless -s option was given,\noutput will match the size of the smallest input.\n"); break; } j=filesize(ifp[i]); } /* And now to figure out the names of our output files... */ - ofname[0] = NULL; + ofname[0][0] = (char)0; for (i=0; i %s)\n", + strerror(errno), ofname[i], buf + ); + } else { fprintf(stderr, "Wrote %s\n", buf); - } + } + } // for i exit(0); -} +} // main() /* Return size of fp passed */ long filesize(FILE *fp) @@ -277,24 +281,24 @@ /* print out the help message */ void printhelp() { - fprintf(stderr, "Usage: pad [options] [input files] - -options: - - -r [num] - Pad will XOR in [num] pads generated from random data. if this - is ommited, pad will use either 1 or 0 random pads, depending on - if there is only one input file or more than one, respectively. - - -o [output] - The result of all the XOR operations will be stored in this - file. If [output] is ommitted, pad will name the file according - to its MD5-sum, along with the rest of the random pads. - - -s [size] - The output data will be [size] bytes. If this is less than the - smallest input file, the output will be clipped to match, if it - is larger, random data will be appended to the end. - - -h - Show usage. - + fprintf(stderr, "Usage: pad [options] [input files]\n\ +\n\ +options:\n\ +\n\ + -r [num] - Pad will XOR in [num] pads generated from random data. if this\n\ + is omitted, pad will use either 1 or 0 random pads, depending on\n\ + if there is only one input file or more than one, respectively.\n\ +\n\ + -o [output] - The result of all the XOR operations will be stored in this\n\ + file. If [output] is omitted, pad will name the file according\n\ + to its MD5-sum, along with the rest of the random pads.\n\ +\n\ + -s [size] - The output data will be [size] bytes. If this is less than the\n\ + smallest input file, the output will be clipped to match, if it\n\ + is larger, random data will be appended to the end.\n\ +\n\ + -h - Show usage.\n\ +\n\ "); } @@ -325,8 +329,8 @@ buf[0] = '\0'; for ( j=0 ; j<16 ; j++ ) { - sprintf(buf, "%s%c", buf, (hexdigits[digest[j]>>4])); - sprintf(buf, "%s%c", buf, (hexdigits[digest[j]&0xf])); + snprintf(buf, sizeof(buf), "%s%c", buf, (hexdigits[digest[j]>>4])); + snprintf(buf, sizeof(buf), "%s%c", buf, (hexdigits[digest[j]&0xf])); } return((char *)strdup(buf)); }