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 <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2021-12-13 21:22:59 +02:00 committed by Xiang Xiao
parent 69468b700d
commit 12b3491208

View File

@ -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;
}