diff options
author | Saju-Mohammed <sajmoham@redhat.com> | 2020-08-04 21:41:24 +0530 |
---|---|---|
committer | msaju <sajmoham@redhat.com> | 2020-08-07 10:21:46 +0530 |
commit | 163aa7d2bcbba71107602ab6672da1af53b31726 (patch) | |
tree | ca7b890f989055b866b93bec115c22e289df3486 /libglusterfs/src/common-utils.c | |
parent | 6e8e73a06d71382f8f6e3cd83fe72692d19e66ba (diff) |
glusterfs: infinite loop in common-utils.c
Issue: function - gf_rev_dns_lookup_cache having an infinite
loop when gf_dnscache_entry_init() returns NULL.
Also when ip address is coming in as NULL.
Fix: Code change has been done to handle the loop.
Also minor CLINT warnings removed for common-utils.c
Added review comment changes.
Code changes for #790
Change-Id: I24446dc64c0409009e91e0bf57a699c85337c578
Fixes: #790
Signed-off-by: msaju <sajmoham@redhat.com>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r-- | libglusterfs/src/common-utils.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 521073d21c4..c37c45449f2 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -438,7 +438,7 @@ gf_resolve_path_parent(const char *path) GF_VALIDATE_OR_GOTO(THIS->name, path, out); - if (strlen(path) <= 0) { + if (0 == strlen(path)) { gf_msg_callingfn(THIS->name, GF_LOG_DEBUG, 0, LG_MSG_INVALID_STRING, "invalid string for 'path'"); goto out; @@ -677,23 +677,16 @@ gf_rev_dns_lookup_cached(const char *ip, struct dnscache *dnscache) from_cache = _gf_false; out: /* Insert into the cache */ - if (fqdn && !from_cache) { + if (fqdn && !from_cache && ip) { struct dnscache_entry *entry = gf_dnscache_entry_init(); - if (!entry) { - goto out; - } - entry->fqdn = fqdn; - if (!ip) { - gf_dnscache_entry_deinit(entry); - goto out; + if (entry) { + entry->fqdn = fqdn; + entry->ip = gf_strdup(ip); + entry->timestamp = time(NULL); + entrydata = bin_to_data(entry, sizeof(*entry)); + dict_set(cache, (char *)ip, entrydata); } - - entry->ip = gf_strdup(ip); - entry->timestamp = time(NULL); - - entrydata = bin_to_data(entry, sizeof(*entry)); - dict_set(cache, (char *)ip, entrydata); } return fqdn; } @@ -4394,7 +4387,7 @@ gf_backtrace_end(char *buf, size_t frames) frames = min(frames, GF_BACKTRACE_LEN - pos - 1); - if (frames <= 0) + if (0 == frames) return; memset(buf + pos, ')', frames); |