This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/18799] New: iconv_prog exit status with -c is inconsistent


https://sourceware.org/bugzilla/show_bug.cgi?id=18799

            Bug ID: 18799
           Summary: iconv_prog exit status with -c is inconsistent
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: ben at 0x539 dot de
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/iconv.html , which
looks reasonably authoritative, says

> -c
>    Omit any characters that are invalid in the codeset of the input file
>    from the output.
>    [...]
>    The presence or absence of -c shall not affect the exit status of iconv.

I believe this means that invalid input sequences should be silently ignored,
but the exit status should still report failure if any were encountered.

iconv_prog.c currently fails to implement that, though the attempt is made: It
records when an invalid input sequence has been encountered and ignored, but it
clobbers the variable if there was any input in the current buffer that has
been successfully converted and needs to be written out (in the process_block
function):

      if (n == (size_t) -1 && omit_invalid && errno == EILSEQ)
        {
          ret = 1;
      [...]
      if (outptr != outbuf)
        {
          ret = write_output (outbuf, outptr, output, output_file);

As a result, we can observe the following when telling iconv_prog to interpret
0xff as an ASCII character:

    $ echo -n $'OK \xff' | iconv -c -f ascii > /dev/null; echo $?
    0

    $ echo -n $'\xff OK' | iconv -c -f ascii > /dev/null; echo $?
    0

    $ echo -n $'\xff' | iconv -c -f ascii > /dev/null; echo $?
    1

    $ (head -c 32769 /dev/zero; echo -n $'\xff') | iconv -c -f ascii >
/dev/null; echo $?
    1

I believe it should exit with non-zero exit status in all of these situations.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]