Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Feb 2016 14:59:59 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-standards@FreeBSD.org
Subject:   [Bug 207544] mbtowc(3) fails to set errno(2) for incomplete characters
Message-ID:  <bug-207544-15@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D207544

            Bug ID: 207544
           Summary: mbtowc(3) fails to set errno(2) for incomplete
                    characters
           Product: Base System
           Version: 11.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: standards
          Assignee: freebsd-standards@FreeBSD.org
          Reporter: schwarze@usta.de

Created attachment 167481
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D167481&action=
=3Dedit
patch against lib/libc/locale/mbtowc.c to fix errno handling

If an incomplete character is passed to mbtowc(3), it fails to set errno to
EILSEQ, even though that is unambiguously required by POSIX.

Setting errno in that case makes a lot of sense because having a function t=
hat
can fail and that sets errno in some failure modes but does not set errno in
other failure modes would be a terrible idea.  Such a function would be
ridiculously complicated to use.  To detect the reason for failure, you wou=
ld
have to:

 - save errno
 - reset errno to zero
 - call the function
 - inspect the return value to detect failure
 - inspect errno to decide about the reason for failure
 - if errno is zero, restore the saved errno

That is completely unreasonable, in particular for a seemingly innocous
function like mbtowc(3).  Next to no programmer would get that right in any
real-world program.

Note that this bug is very widespread, it also affects Solaris 11 and glibc,
and also OpenBSD until i fixed it today.  I will also send a note around to=
 the
other systems.

The OpenBSD commit will soon show up here:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/locale/mbtowc.c

The attachment contains a patch against FreeBSD-current, mainly to make it =
even
clearer what exactly i mean.  Note that i did not test the patch since i do=
n't
have a FreeBSD system - so please test before commit!  Thanks.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-207544-15>