diff options
author | Michal Zidek <mzidek@redhat.com> | 2013-09-10 23:09:04 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-12-10 12:04:50 +0100 |
commit | 8bf65dbab8703697c85b033beb5c189fce17b036 (patch) | |
tree | eb99c28b6e004fc6c05ede4a7cdc30569cce7dbf /src/sss_client | |
parent | 65f4003b93157b32eb0dcd6955d37dd009dc960e (diff) | |
download | sssd-8bf65dbab8703697c85b033beb5c189fce17b036.tar.gz sssd-8bf65dbab8703697c85b033beb5c189fce17b036.tar.xz sssd-8bf65dbab8703697c85b033beb5c189fce17b036.zip |
Properly align buffer when storing pointers.
Properly align buffer address to sizeof(char *) when storing
pointers to strings.
resolves:
https://fedorahosted.org/sssd/ticket/1359
Diffstat (limited to 'src/sss_client')
-rw-r--r-- | src/sss_client/nss_group.c | 8 | ||||
-rw-r--r-- | src/sss_client/nss_mc_group.c | 10 | ||||
-rw-r--r-- | src/sss_client/nss_services.c | 7 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index a7fb09375..9e259318d 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -233,14 +233,12 @@ static int sss_nss_getgr_readrep(struct sss_nss_gr_rep *pr, NULL); if (ret != EOK) return ret; - /* Make sure pr->buffer[i+pad] is 32 bit aligned */ - pad = 0; - while((i + pad) % 4) { - pad++; - } + /* Make sure pr->buffer[i+pad] is aligned to sizeof(char *) */ + pad = PADDING_SIZE(i, char *); /* now members */ pr->result->gr_mem = (char **)&(pr->buffer[i+pad]); + ptmem = (sizeof(char *) * (mem_num + 1)) + pad; if (ptmem > dlen) { return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */ diff --git a/src/sss_client/nss_mc_group.c b/src/sss_client/nss_mc_group.c index 5610233ed..fb5e43f84 100644 --- a/src/sss_client/nss_mc_group.c +++ b/src/sss_client/nss_mc_group.c @@ -27,6 +27,7 @@ #include <sys/mman.h> #include <time.h> #include "nss_mc.h" +#include "util/util_safealign.h" struct sss_cli_mc_ctx gr_mc_ctx = { false, -1, 0, NULL, 0, NULL, 0, NULL, 0 }; @@ -64,7 +65,14 @@ static errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec, /* fill in group */ result->gr_gid = data->gid; - result->gr_mem = (char **)buffer; + + /* The address &buffer[0] must be aligned to sizeof(char *) */ + if (!IS_ALIGNED(buffer, char *)) { + /* The buffer is not properly aligned. */ + return EFAULT; + } + + result->gr_mem = (char **)DISCARD_ALIGN(buffer); result->gr_mem[data->members] = NULL; cookie = NULL; diff --git a/src/sss_client/nss_services.c b/src/sss_client/nss_services.c index b40e1fa94..e89e0d2f1 100644 --- a/src/sss_client/nss_services.c +++ b/src/sss_client/nss_services.c @@ -127,11 +127,8 @@ sss_nss_getsvc_readrep(struct sss_nss_svc_rep *sr, NULL); if (ret != EOK) return ret; - /* Make sure sr->buffer[i+pad] is 32-bit aligned */ - pad = 0; - while((i + pad) % 4) { - pad++; - } + /* Make sure sr->buffer[i+pad] is aligned to sizeof(char *) */ + pad = PADDING_SIZE(i, char *); /* Copy in the aliases */ sr->result->s_aliases = (char **) &(sr->buffer[i+pad]); |