Project

General

Profile

Actions

Bug #13021

closed

Invalid state if bindtextdomain() fails during re-binding

Added by Richard Hansen 10 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
lib - userland libraries
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
Gerrit CR:

Description

When re-binding an already-bound text domain, bindtextdomain() first frees the existing binding then strdup()s the new directory. If the strdup() call fails, the net effect is the old binding is replaced with a null pointer. Contrary to the man page, future queries (via bindtextdomain(domain, NULL)) will return a null pointer, not the old binding nor the default /usr/lib/locale.

Proposed fix: First strdup() the new directory and only update the binding if strdup() succeeds.

Users are unlikely to encounter this bug in practice, but the Austin group is currently working on standardizing gettext() and friends for inclusion in the next version of the POSIX standard. We are using illumos as one of our references to ensure that the resulting standard agrees with existing practice. How (or if) this bug is resolved could impact the wording that will appear in the POSIX standard.

Actions #1

Updated by Electric Monk 10 months ago

  • Gerrit CR set to 838
Actions #2

Updated by Richard Hansen 10 months ago

Results from running the new unit tests (with -f) against an unpatched libc:

TEST STARTING unbound query (amd64):
TEST PASS: unbound query (amd64)
TEST STARTING bind malloc fail (amd64):
TEST PASS: bind malloc fail (amd64)
TEST STARTING query after bind malloc fail (amd64):
TEST PASS: query after bind malloc fail (amd64)
TEST STARTING normal bind (amd64):
TEST PASS: normal bind (amd64)
TEST STARTING query after normal bind (amd64):
TEST PASS: query after normal bind (amd64)
TEST STARTING rebind to same (amd64):
TEST PASS: rebind to same (amd64)
TEST STARTING query after rebind to same (amd64):
TEST PASS: query after rebind to same (amd64)
TEST STARTING rebind to new (amd64):
TEST PASS: rebind to new (amd64)
TEST STARTING query after rebind to new (amd64):
TEST PASS: query after rebind to new (amd64)
TEST STARTING rebind malloc fail (amd64):
TEST PASS: rebind malloc fail (amd64)
TEST STARTING query after rebind malloc fail (amd64):
TEST FAILING query after rebind malloc fail (amd64): returned <NULL>, want /bounddir3
TEST FAILED: 1 failures
TEST SUMMARY: 10 / 11 (1 failing)

Results from running the new unit tests against a patched libc:

TEST STARTING unbound query (amd64):
TEST PASS: unbound query (amd64)
TEST STARTING bind malloc fail (amd64):
TEST PASS: bind malloc fail (amd64)
TEST STARTING query after bind malloc fail (amd64):
TEST PASS: query after bind malloc fail (amd64)
TEST STARTING normal bind (amd64):
TEST PASS: normal bind (amd64)
TEST STARTING query after normal bind (amd64):
TEST PASS: query after normal bind (amd64)
TEST STARTING rebind to same (amd64):
TEST PASS: rebind to same (amd64)
TEST STARTING query after rebind to same (amd64):
TEST PASS: query after rebind to same (amd64)
TEST STARTING rebind to new (amd64):
TEST PASS: rebind to new (amd64)
TEST STARTING query after rebind to new (amd64):
TEST PASS: query after rebind to new (amd64)
TEST STARTING rebind malloc fail (amd64):
TEST PASS: rebind malloc fail (amd64)
TEST STARTING query after rebind malloc fail (amd64):
TEST PASS: query after rebind malloc fail (amd64)
TEST SUMMARY: 11 / 11 (ok)

Actions #3

Updated by Electric Monk 10 months ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit 0a9a25a293d437b1563e1d8479fef8f3795ba817

commit  0a9a25a293d437b1563e1d8479fef8f3795ba817
Author: Richard Hansen <rhansen@rhansen.org>
Date:   2020-08-23T23:39:37.000Z

    13021 Invalid state if bindtextdomain() fails during re-binding
    Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
    Approved by: Dan McDonald <danmcd@joyent.com>

Actions

Also available in: Atom PDF