Bug 6392 - [PATCH] log2pcaphex: uncorrect behavior when we cannot open output file
[PATCH] log2pcaphex: uncorrect behavior when we cannot open output file
Status: RESOLVED FIXED
Product: Samba 4.0
Classification: Unclassified
Component: Other
unspecified
All All
: P3 trivial
: ---
Assigned To: Volker Lendecke
Andrew Bartlett
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-05-22 13:33 UTC by Slava Semushin
Modified: 2009-06-05 03:14 UTC (History)
0 users

See Also:


Attachments
Really use stdout if file cannot be opened. (717 bytes, patch)
2009-05-22 13:35 UTC, Slava Semushin
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Slava Semushin 2009-05-22 13:33:43 UTC
Looks like a bug:

	const char *infile, *outfile;
	FILE *out, *in;
...
	outfile = poptGetArg(pc);

	if(outfile) {
		out = fopen(outfile, "w+");
		if(!out) { 
			perror("fopen"); 
			fprintf(stderr, "Can't find %s, using stdout...\n", outfile);
		}
	}

	if(!outfile) out = stdout;

When we can't open specified file program should use stdout, but out variable not assigned to stdout because outfile contains filename.

So, we should NULL'ify outfile to pass this checks, or change condition to compare out with NULL (in this case we also should initialize this variable).

I made a trivial patch which just assign NULL to outfile when we can't open file.
Comment 1 Slava Semushin 2009-05-22 13:35:01 UTC
Created attachment 4186 [details]
Really use stdout if file cannot be opened.

Proposal fix.
Comment 2 Volker Lendecke 2009-05-25 09:30:53 UTC
I'd rather see the program to exit if we can't open a file a user explicitly asked to open. Do you want to provide a new patch with that, or do you want me to do it?

Thanks,

Volker
Comment 3 Slava Semushin 2009-05-25 12:04:14 UTC
(In reply to comment #2)
> I'd rather see the program to exit if we can't open a file a user explicitly
> asked to open. Do you want to provide a new patch with that, or do you want me
> to do it?

It's not my idea, so I think it would be better if you implement it.

Comment 4 Volker Lendecke 2009-06-05 03:14:20 UTC
Pushed to master with c8d63d47cd38. I hope you don't mind I don't push this into the other branches, I don't think this is really criticial enough.

Thanks,

Volker