X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/1efaa59e478c7de42890607766af574547e74a04..1afd3f308e25f7bf070f3932a28ed6b2be8173f6:/tcpdump.c diff --git a/tcpdump.c b/tcpdump.c index 6103efa7..c43ab854 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -589,6 +589,8 @@ static void MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars) { char *filename = malloc(NAME_MAX + 1); + if (filename == NULL) + error("Makefilename: malloc); /* Process with strftime if Gflag is set. */ if (Gflag != 0) { @@ -651,6 +653,19 @@ struct print_info get_print_info(int type) { return (printinfo); } +char *get_next_file(FILE *VFile, char *ptr) { + char *ret; + + ret = fgets(ptr, NAME_MAX, VFile); + if (!ret) + return NULL; + + if (ptr[strlen(ptr) - 1] == '\n') + ptr[strlen(ptr) - 1] = '\0'; + + return ret; +} + int main(int argc, char **argv) { @@ -1138,19 +1153,16 @@ main(int argc, char **argv) #endif /* WIN32 */ if (VFileName != NULL) { if (VFileName[0] == '-' && VFileName[1] == '\0') - VFile = fopen("/dev/stdin", "r"); + VFile = stdin; else VFile = fopen(VFileName, "r"); if (VFile == NULL) error("Unable to open file: %s\n", strerror(errno)); - ret = fgets(VFileLine, NAME_MAX, VFile); + ret = get_next_file(VFile, VFileLine); if (!ret) - error("Nothing in %s\n", VFile); - - if (VFileLine[strlen(VFileLine) - 1] == '\n') - VFileLine[strlen(VFileLine) - 1] = '\0'; + error("Nothing in %s\n", VFileName); RFileName = VFileLine; } @@ -1519,10 +1531,8 @@ main(int argc, char **argv) } pcap_close(pd); if (VFileName != NULL) { - ret = fgets(VFileLine, NAME_MAX, VFile); + ret = get_next_file(VFile, VFileLine); if (ret) { - if (VFileLine[strlen(VFileLine) - 1] == '\n') - VFileLine[strlen(VFileLine) - 1] = '\0'; RFileName = VFileLine; pd = pcap_open_offline(RFileName, ebuf); if (pd == NULL)