Bug 261679 - libc/locale/xlocale.c: potential NULL pointer dereference in alloc_locale()
Summary: libc/locale/xlocale.c: potential NULL pointer dereference in alloc_locale()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-02 16:59 UTC by phil.stone
Modified: 2022-05-17 18:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description phil.stone 2022-02-02 16:59:49 UTC
/usr/src/lib/libc/locale/xlocale.c, line 191

static locale_t
alloc_locale(void)
{
	locale_t new = calloc(sizeof(struct _xlocale), 1);

	new->header.destructor = destruct_locale;
	new->monetary_locale_changed = 1;
	new->numeric_locale_changed = 1;
	return (new);
}

calloc() return value is not tested. Variable new is always dereferenced, even in the (unexpected) case where it is NULL.
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2022-02-02 17:35:48 UTC
See https://reviews.freebsd.org/D34140
Comment 2 commit-hook freebsd_committer freebsd_triage 2022-02-03 02:50:37 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b68522308d1e0b19c00d82c13878a693fc2ef2df

commit b68522308d1e0b19c00d82c13878a693fc2ef2df
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-02-02 17:24:42 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-02-03 01:02:58 +0000

    xlocale.c: check for allocation failure

    PR:     261679
    Reported by:    phil.stone@gmx.com
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D34140

 lib/libc/locale/xlocale.c | 3 +++
 1 file changed, 3 insertions(+)
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-02-09 00:49:11 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3e4e8d5cbfcd2161d7cdd513ad9d7d88f703fcb8

commit 3e4e8d5cbfcd2161d7cdd513ad9d7d88f703fcb8
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-02-02 17:24:42 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-02-09 00:42:45 +0000

    xlocale.c: check for allocation failure

    PR:     261679

    (cherry picked from commit b68522308d1e0b19c00d82c13878a693fc2ef2df)

 lib/libc/locale/xlocale.c | 3 +++
 1 file changed, 3 insertions(+)