From nobody Sun Nov 03 17:00:27 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XhLSq36Lzz5cRsM; Sun, 03 Nov 2024 17:00:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XhLSq2gqPz4bgv; Sun, 3 Nov 2024 17:00:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730653227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ro3wxsgihfay5sgxVw7ldcC3mHNqwzOofH8iRbOiCdA=; b=qnN12l6cI5Hyc2WTojCQP07hIEujuKGDjl/FjP9EhUfoU8xFAY4LOUu+cc2vekc++9Rast hbEiVVyLvrMlZBiiaFlgfkIa1U033Q70S1/gAeUBixqLdsP/AYYJa7dWPxYQfpgif/txe9 sbzjzWu5LeDEZZpqswpdfwmRB3AfujW/NLZBhxn0tG1TmeljECE/yooQ3Pnds8FPUNBYQV 0LQ1A94AVEtUFo/e2h61HVnxHLPliwNcSajuY92nxhBTBhdEBBD1hWXQFrKWJm/TWasy5K l0/ElvBdu3T+qdvXNCg0H5rDeJiVgmhPF1nASRNwn0/RgujRVC+VOjRDjULSmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730653227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ro3wxsgihfay5sgxVw7ldcC3mHNqwzOofH8iRbOiCdA=; b=CTJHze2Nqd1qG9Ila+iVWo2OTay39QCadgn98ia9s4e5bSHzIk1Wq8UhsBI7OMnjbdrLRY FRtQ5XbROlgwp+14GWSV8Jvt4z/4vlLKIkfcKl9NCXhQ9WalGQf68LoMyAH5m2HIgApEY2 0ZScEq64KPUnWcU0QJfDZ9ZyfOKUZFaa+xMrNE5Co56Qiye9kFEz7kuGiMumgW4P4SADk0 nfK/Gp4faLsDdhd7xaOcnkI1sXlgyHDvsbMc6Oqna4/xJozdMj2bd7m23FSyOEdPxdzRzt PlI/c93sdYh6aTNuKFn3I3s1ZcwpSO7iNOIst9WRWrUJYiVdYkABP09bAUd6Hw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730653227; a=rsa-sha256; cv=none; b=TrtVIu9zRzbnZFLkCQZ3VXM9FqUxgIalU5GEKNov4a3GRN7XEejl6qFYRcuN63+oxgNu3x ACoOIC6YB9v07bUeoFs89GFmYZak9Q6ZB8nP4k75tQqA73LgaTD7jj/qvFk+WktohhhriF mbQuARu3zStruwMJ4htyue7gVhef6giFv4nb0YRJakXUnZHNocMQKeaU49SRWuztxys1MT VvrWvIx0Dc1uLMhR25PYIuT8WO/h/XF7zG8huJHcXyjURSVdR4l671bJ0yrM02Qzeywnxs qY/RFnVotoXx+8oKCGYKveSlJUjLOy9JqM53DnXoy0q64rRrv7UFprLMNWkN7Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XhLSq2HC8zxJp; Sun, 3 Nov 2024 17:00:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A3H0RXq021401; Sun, 3 Nov 2024 17:00:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A3H0RGw021398; Sun, 3 Nov 2024 17:00:27 GMT (envelope-from git) Date: Sun, 3 Nov 2024 17:00:27 GMT Message-Id: <202411031700.4A3H0RGw021398@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 1176390d2d2b - main - catopen(3): align returned errors with IEEE Std =?utf-8?Q?1003.1=E2=84=A2-2024?= List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1176390d2d2bbb1e207c840d1f7a66a6ac1096ff Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1176390d2d2bbb1e207c840d1f7a66a6ac1096ff commit 1176390d2d2bbb1e207c840d1f7a66a6ac1096ff Author: Konstantin Belousov AuthorDate: 2024-11-03 12:50:32 +0000 Commit: Konstantin Belousov CommitDate: 2024-11-03 16:59:15 +0000 catopen(3): align returned errors with IEEE Std 1003.1™-2024 - Invalid/non-existent/unable to use message catalog file should result in ENOENT, and not in EFTYPE. - Added detection of several cases of wrong file format due to length [*]. - Update man page. * Based on the original patch from PR. PR: 172805 Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47413 --- lib/libc/nls/catopen.3 | 13 +++++++------ lib/libc/nls/msgcat.c | 30 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/libc/nls/catopen.3 b/lib/libc/nls/catopen.3 index 6fd50956be1f..6fb2e2522e85 100644 --- a/lib/libc/nls/catopen.3 +++ b/lib/libc/nls/catopen.3 @@ -130,16 +130,17 @@ Otherwise, (nl_catd) -1 is returned and is set to indicate the error. .Sh ERRORS .Bl -tag -width Er -.It Bq Er EINVAL -Argument -.Fa name -does not point to a valid message catalog, or catalog is corrupt. .It Bq Er ENAMETOOLONG An entire path to the message catalog exceeded 1024 characters. .It Bq Er ENOENT -The named message catalog does not exists, or the +Argument .Fa name -argument points to an empty string. +does not point to a valid message catalog name, +or it points to an empty string. +.It Bq Er ENOENT +The named message catalog does not exist. +.It Bq Er ENOENT +The named message catalog file is in wrong format. .It Bq Er ENOMEM Insufficient memory is available. .El diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c index 32fa191c4c67..61c09b65f434 100644 --- a/lib/libc/nls/msgcat.c +++ b/lib/libc/nls/msgcat.c @@ -136,7 +136,7 @@ __catopen_l(const char *name, int type, locale_t locale) /* sanity checking */ if (name == NULL || *name == '\0') - NLRETERR(EINVAL); + NLRETERR(ENOENT); if (strchr(name, '/') != NULL) /* have a pathname */ @@ -390,7 +390,7 @@ load_msgcat(const char *path, const char *name, const char *lang) struct catentry *np; void *data; char *copy_path, *copy_name, *copy_lang; - int fd; + int fd, saved_errno; /* path/name will never be NULL here */ @@ -414,9 +414,17 @@ load_msgcat(const char *path, const char *name, const char *lang) } if (_fstat(fd, &st) != 0) { + saved_errno = errno; _close(fd); - SAVEFAIL(name, lang, EFTYPE); - NLRETERR(EFTYPE); + SAVEFAIL(name, lang, saved_errno); + NLRETERR(saved_errno); + } + + /* The file is too small to contain a _NLS_MAGIC. */ + if (st.st_size < sizeof(u_int32_t)) { + _close(fd); + SAVEFAIL(name, lang, ENOENT); + NLRETERR(ENOENT); } /* @@ -426,13 +434,13 @@ load_msgcat(const char *path, const char *name, const char *lang) */ if (st.st_size > SIZE_T_MAX) { _close(fd); - SAVEFAIL(name, lang, EFBIG); - NLRETERR(EFBIG); + SAVEFAIL(name, lang, ENOENT); + NLRETERR(ENOENT); } - if ((data = mmap(0, (size_t)st.st_size, PROT_READ, - MAP_FILE|MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) { - int saved_errno = errno; + data = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (data == MAP_FAILED) { + saved_errno = errno; _close(fd); SAVEFAIL(name, lang, saved_errno); NLRETERR(saved_errno); @@ -442,8 +450,8 @@ load_msgcat(const char *path, const char *name, const char *lang) if (ntohl((u_int32_t)((struct _nls_cat_hdr *)data)->__magic) != _NLS_MAGIC) { munmap(data, (size_t)st.st_size); - SAVEFAIL(name, lang, EFTYPE); - NLRETERR(EFTYPE); + SAVEFAIL(name, lang, ENOENT); + NLRETERR(ENOENT); } copy_name = strdup(name);