Bug 5903 - "iconv" creates unnecessary output
Summary: "iconv" creates unnecessary output
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ryan S. Arnold
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-10 12:57 UTC by Tit Couille
Modified: 2014-07-02 06:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tit Couille 2008-03-10 12:57:58 UTC
This bug concerns the "iconv" utility. It's not really a bug, but bad design. I did:

iconv --from-code==LATIN1 --to-code=UTF-8 --output=file_to_convert.xml
output_file.xml

where mistakingly I had put my original file, file_to_convert.xml, as output
file. And for source file I had specified mistakingly some output filename which
doesn't exist. So iconv displayed that "output_file.xml" doesn't exist, that it
can't read from it, but replaced my original file (file_to_convert.xml) with an
empty 0-byte file. But it's stupid that it would put an empty file (and thus
destroy all my data) when there was nothing to convert in the first place.

To sum it up, don't create an output file when there isn't an input file.
Comment 1 Ryan S. Arnold 2008-03-10 21:17:35 UTC
In libc/iconv/iconv_prog.c the output_file is fopen'ed prior to processing any
of the files specified on the command line.

Perhaps a lazy fopen() of the output_file can take place when an actual
fopen(argv[remaining]) succeeds.

I'll investigate.

Comment 2 Ulrich Drepper 2008-03-11 20:13:30 UTC
I checked in a patch to the trunk.