This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 12b3491 libc/textdomain: Fix error behaviour
12b3491 is described below
commit 12b34912086ff5007ac14e6397f622ad3ac98ad1
Author: Petro Karashchenko <[email protected]>
AuthorDate: Mon Dec 13 21:22:59 2021 +0200
libc/textdomain: Fix error behaviour
- textdomain should set errno to ENOMEM in case if it is not
possible to store domainname
- fix buffer overflow in textdomain if domainname is a string
of NAME_MAX length
- improve textdomain error detection in case if domainname
points to non null terminated buffer
Signed-off-by: Petro Karashchenko <[email protected]>
---
libs/libc/locale/lib_gettext.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libs/libc/locale/lib_gettext.c b/libs/libc/locale/lib_gettext.c
index d0c52d8..cb16c2e 100644
--- a/libs/libc/locale/lib_gettext.c
+++ b/libs/libc/locale/lib_gettext.c
@@ -373,10 +373,10 @@ FAR char *textdomain(FAR const char *domainname)
return *domain ? domain : "messages";
}
- domainlen = strlen(domainname);
- if (domainlen > NAME_MAX)
+ domainlen = strnlen(domainname, NAME_MAX);
+ if (domainlen == NAME_MAX)
{
- set_errno(EINVAL);
+ set_errno(ENOMEM);
return NULL;
}