diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2010-02-10 13:01:33 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-02-18 13:48:44 -0500 |
commit | 29e9f5e711a03135944e30ad241c8182dacc6049 (patch) | |
tree | 0da07910b6618ced8b16d0011ad023687efed7cc /server/providers/ldap/ldap_child.c | |
parent | 2c5bf74c71443f1680fef4fc0daa4a4c9dd10ad8 (diff) | |
download | sssd-29e9f5e711a03135944e30ad241c8182dacc6049.tar.gz sssd-29e9f5e711a03135944e30ad241c8182dacc6049.tar.bz2 sssd-29e9f5e711a03135944e30ad241c8182dacc6049.zip |
Use macros to hide memcpy calls
The memcpy calls introduced in the memalign patches are ugly. This patch
hides them behind a set of macros.
Diffstat (limited to 'server/providers/ldap/ldap_child.c')
-rw-r--r-- | server/providers/ldap/ldap_child.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/server/providers/ldap/ldap_child.c b/server/providers/ldap/ldap_child.c index 448a9cc6..0d34be2c 100644 --- a/server/providers/ldap/ldap_child.c +++ b/server/providers/ldap/ldap_child.c @@ -48,14 +48,10 @@ static errno_t unpack_buffer(uint8_t *buf, size_t size, size_t p = 0; uint32_t len; - /* realm_str size and length */ DEBUG(7, ("total buffer size: %d\n", size)); - if ((p + sizeof(uint32_t)) > size) { - DEBUG(1, ("Error: buffer too big!\n")); - return EINVAL; - } - memcpy(&len, buf + p, sizeof(uint32_t)); - p += sizeof(uint32_t); + + /* realm_str size and length */ + COPY_UINT32_CHECK(&len, buf + p, p, size); DEBUG(7, ("realm_str size: %d\n", len)); if (len) { @@ -67,9 +63,7 @@ static errno_t unpack_buffer(uint8_t *buf, size_t size, } /* princ_str size and length */ - if ((p + sizeof(uint32_t)) > size) return EINVAL; - memcpy(&len, buf + p, sizeof(uint32_t)); - p += sizeof(uint32_t); + COPY_UINT32_CHECK(&len, buf + p, p, size); DEBUG(7, ("princ_str size: %d\n", len)); if (len) { @@ -81,9 +75,7 @@ static errno_t unpack_buffer(uint8_t *buf, size_t size, } /* keytab_name size and length */ - if ((p + sizeof(uint32_t)) > size) return EINVAL; - memcpy(&len, buf + p, sizeof(uint32_t)); - p += sizeof(uint32_t); + COPY_UINT32_CHECK(&len, buf + p, p, size); DEBUG(7, ("keytab_name size: %d\n", len)); if (len) { @@ -101,24 +93,18 @@ static int pack_buffer(struct response *r, int result, const char *msg) { int len; int p = 0; - uint32_t c; len = strlen(msg); r->size = 2 * sizeof(uint32_t) + len; /* result */ - c = result; - memcpy(&r->buf[p], &c, sizeof(uint32_t)); - p += sizeof(uint32_t); + COPY_UINT32_VALUE(&r->buf[p], result, p); /* message size */ - c = len; - memcpy(&r->buf[p], &c, sizeof(uint32_t)); - p += sizeof(uint32_t); + COPY_UINT32_VALUE(&r->buf[p], len, p); /* message itself */ - memcpy(&r->buf[p], msg, len); - p += len; + COPY_MEM(&r->buf[p], msg, p, len); return EOK; } |