diff options
Diffstat (limited to 'src/openlmi.c')
-rw-r--r-- | src/openlmi.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/openlmi.c b/src/openlmi.c index 786bdd2..c6d808e 100644 --- a/src/openlmi.c +++ b/src/openlmi.c @@ -34,11 +34,19 @@ static int _log_level = _LMI_DEBUG_DEBUG; static const CMPIBroker *_cb = NULL; static char *_log_id = NULL; +/** Gets Fully Quantified Domain Name of the system + * @return FQDN (must be freed by the caller) + */ static char *getFQDN(void) { struct utsname uts; - if ((uname(&uts) > 0) && (uts.nodename != NULL)) { - return strdup(uts.nodename); + if ((uname(&uts) > 0) && (strlen(uts.nodename) > 0)) { + char *nodename; + if ((nodename = strdup(uts.nodename)) == NULL) { + lmi_error("Memory allocation failed"); + return NULL; + } + return nodename; } char hostname[256]; hostname[255] = '\0'; @@ -59,6 +67,10 @@ static char *getFQDN(void) if (p->ai_canonname && strstr(p->ai_canonname, "localhost") == NULL) { char *dn = strdup(p->ai_canonname); freeaddrinfo(info); + if (dn == NULL) { + lmi_error("Memory allocation failed"); + return NULL; + } return dn; } } |