Bug 827510 - newlocale() doesn't always set errno upon failure return
newlocale() doesn't always set errno upon failure return
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
16
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Jeff Law
Fedora Extras Quality Assurance
:
Depends On:
Blocks: 832516
  Show dependency treegraph
 
Reported: 2012-06-01 12:20 EDT by Tom Lane
Modified: 2016-11-24 10:37 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 832516 (view as bug list)
Environment:
Last Closed: 2012-06-14 23:52:53 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 14247 None None None Never

  None (edit)
Description Tom Lane 2012-06-01 12:20:17 EDT
Description of problem:
newlocale() neglects to set errno to an appropriate value when failing, if it has already been asked about the same incorrect locale name.

Version-Release number of selected component (if applicable):
glibc-2.14.90-24.fc16.7.x86_64

How reproducible:
100%

Steps to Reproduce:
Run this program:

#include <stdio.h>
#include <errno.h>
#include <locale.h>

int
main(int argc, char **argv)
{
  locale_t loc;

  setlocale(LC_ALL, "C");

  errno = 0;
  loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK,
		  "nb_no.utf8",
		  0);
  printf("result = %p errno = %d\n", loc, errno);

  errno = 0;
  loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK,
		  "nb_no.utf8",
		  0);
  printf("result = %p errno = %d\n", loc, errno);

  return 0;
}

  
Actual results:
result = (nil) errno = 2
result = (nil) errno = 0

Expected results:
result = (nil) errno = 2
result = (nil) errno = 2     (or at least something other than 0)

Additional info:
The problem appears to be that newlocale relies entirely on failure of an underlying open() call to set errno for such cases.  In the case where the "decided" flag is already set, no new open() calls occur, so errno doesn't get set.

I read POSIX:2008 to require errno to be set upon failure return:

Upon failure, the newlocale() function shall return ( locale_t)0 and set errno to indicate the error.
Comment 4 Fedora Update System 2012-06-18 14:42:21 EDT
glibc-2.15-47.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/glibc-2.15-47.fc17
Comment 5 Fedora Update System 2012-07-02 11:40:36 EDT
glibc-2.15-50.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/glibc-2.15-50.fc17
Comment 6 Fedora Update System 2012-07-19 05:15:00 EDT
glibc-2.15-51.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.