Skip to content

Commit 7c59cf1

Browse files
committed
common/common.c: extend xstrdup() definition to return NULL if input was NULL (and log it) [#2052]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 05edad7 commit 7c59cf1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

common/common.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,14 @@ void *xrealloc(void *ptr, size_t size)
17381738

17391739
char *xstrdup(const char *string)
17401740
{
1741-
char *p = strdup(string);
1741+
char *p;
1742+
1743+
if (string == NULL) {
1744+
upsdebugx(1, "%s: got null input", __func__);
1745+
return NULL;
1746+
}
1747+
1748+
p = strdup(string);
17421749

17431750
if (p == NULL)
17441751
fatal_with_errno(EXIT_FAILURE, "%s", oom_msg);

0 commit comments

Comments
 (0)