diff options
author | Michal Zidek <mzidek@redhat.com> | 2013-08-14 18:01:30 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-08-19 20:51:03 +0200 |
commit | e61044d99ce1e68057fda236f04a731f1f3f299a (patch) | |
tree | 6f8f2f97ed7f703b51baa3ab6d63be31346c4803 /src/sss_client/nss_mc_group.c | |
parent | 8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6 (diff) | |
download | sssd-e61044d99ce1e68057fda236f04a731f1f3f299a.tar.gz sssd-e61044d99ce1e68057fda236f04a731f1f3f299a.tar.xz sssd-e61044d99ce1e68057fda236f04a731f1f3f299a.zip |
mmap_cache: Remove triple checks in client code.
We had pattern in client code with 3 conditions
that can be replaced with one.
Diffstat (limited to 'src/sss_client/nss_mc_group.c')
-rw-r--r-- | src/sss_client/nss_mc_group.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/src/sss_client/nss_mc_group.c b/src/sss_client/nss_mc_group.c index da5da0411..9fe72a60e 100644 --- a/src/sss_client/nss_mc_group.c +++ b/src/sss_client/nss_mc_group.c @@ -117,16 +117,11 @@ errno_t sss_nss_mc_getgrnam(const char *name, size_t name_len, /* hashes are calculated including the NULL terminator */ hash = sss_nss_mc_hash(&gr_mc_ctx, name, name_len + 1); slot = gr_mc_ctx.hash_table[hash]; - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - return ENOENT; - } - - while (slot != MC_INVALID_VAL) { - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - /* This probably means that the memory cache was corrupted. */ - return ENOENT; - } + /* If slot is not within the bounds of mmaped region and + * it's value is not MC_INVALID_VAL, then the cache is + * probbably corrupted. */ + while (slot < MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = sss_nss_mc_get_record(&gr_mc_ctx, slot, &rec); if (ret) { goto done; @@ -160,7 +155,7 @@ errno_t sss_nss_mc_getgrnam(const char *name, size_t name_len, slot = rec->next; } - if (slot == MC_INVALID_VAL) { + if (slot >= MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = ENOENT; goto done; } @@ -197,16 +192,11 @@ errno_t sss_nss_mc_getgrgid(gid_t gid, /* hashes are calculated including the NULL terminator */ hash = sss_nss_mc_hash(&gr_mc_ctx, gidstr, len+1); slot = gr_mc_ctx.hash_table[hash]; - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - return ENOENT; - } - - while (slot != MC_INVALID_VAL) { - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - /* This probably means that the memory cache was corrupted. */ - return ENOENT; - } + /* If slot is not within the bounds of mmaped region and + * it's value is not MC_INVALID_VAL, then the cache is + * probbably corrupted. */ + while (slot < MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = sss_nss_mc_get_record(&gr_mc_ctx, slot, &rec); if (ret) { goto done; @@ -227,7 +217,7 @@ errno_t sss_nss_mc_getgrgid(gid_t gid, slot = rec->next; } - if (slot == MC_INVALID_VAL) { + if (slot >= MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = ENOENT; goto done; } |