]> arthur.barton.de Git - netatalk.git/commitdiff
Fix possible alignment violations due to bad casts
authorFrank Lahm <franklahm@googlemail.com>
Wed, 11 Jul 2012 13:22:31 +0000 (15:22 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 11 Jul 2012 13:22:31 +0000 (15:22 +0200)
etc/afpd/acls.c
etc/afpd/directory.c
etc/cnid_dbd/dbd_getstamp.c
etc/uams/uams_dhx2_pam.c
etc/uams/uams_dhx2_passwd.c
libatalk/acl/uuid.c
libatalk/vfs/ea_ad.c

index e37c6262bf4264e9766eaa1550efa2073f67f805..305ef06fed6c65a7cf15e6dbe8e50f325f3f8736 100644 (file)
@@ -991,7 +991,7 @@ static int get_and_map_acl(char *name, char *rbuf, size_t *rbuflen)
     EC_INIT;
     int mapped_aces = 0;
     int dirflag;
-    uint32_t *darwin_ace_count = (uint32_t *)rbuf;
+    char *darwin_ace_count = rbuf;
 #ifdef HAVE_SOLARIS_ACLS
     int ace_count = 0;
     ace_t *aces = NULL;
@@ -1040,8 +1040,9 @@ static int get_and_map_acl(char *name, char *rbuf, size_t *rbuflen)
 
     LOG(log_debug, logtype_afpd, "get_and_map_acl: mapped %d ACEs", mapped_aces);
 
-    *darwin_ace_count = htonl(mapped_aces);
     *rbuflen += sizeof(darwin_acl_header_t) + (mapped_aces * sizeof(darwin_ace_t));
+    mapped_aces = htonl(mapped_aces);
+    memcpy(darwin_ace_count, &mapped_aces, sizeof(uint32_t));
 
     EC_STATUS(0);
 
index 7539d3ba8dbd1f28154053450d92b4d9a3d70ad7..ed40a26a7faf5e330ea8739386e33979e02de26f 100644 (file)
@@ -1881,9 +1881,12 @@ int setdirparams(struct vol *vol, struct path *path, uint16_t d_bitmap, char *bu
         case DIRPBIT_FINFO :
             if (isad) {
                 /* Fixes #2802236 */
-                uint16_t *fflags = (uint16_t *)(finder_buf + FINDERINFO_FRFLAGOFF);
-                *fflags &= htons(~FINDERINFO_ISHARED);
+                uint16_t fflags;
+                memcpy(&fflags, finder_buf + FINDERINFO_FRFLAGOFF, sizeof(uint16_t));
+                fflags &= htons(~FINDERINFO_ISHARED);
+                memcpy(finder_buf + FINDERINFO_FRFLAGOFF, &fflags, sizeof(uint16_t));
                 /* #2802236 end */
+
                 if (  dir->d_did == DIRDID_ROOT ) {
                     /*
                      * Alright, we admit it, this is *really* sick!
index b805d42863366310bc803a0178518c6794a0de3b..197a6db12087eb2f35e052ba5b0c29f30e34d398 100644 (file)
@@ -51,10 +51,6 @@ int dbd_getstamp(DBD *dbd, struct cnid_dbd_rqst *rqst _U_, struct cnid_dbd_rply
     
     rply->namelen = CNID_DEV_LEN;
     rply->name = (char *)data.data + CNID_DEV_OFS;
-    
-
-    LOG(log_debug, logtype_cnid, "cnid_getstamp: Returning stamp '%08x'", *(uint32_t *)rply->name);
-
     rply->result = CNID_DBD_RES_OK;
     return 1;
 }
index 0f0c8a535329b579bac63659a88b41194f481b59..32958f851335ec299050b960b5ada7148051088d 100644 (file)
@@ -242,6 +242,7 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     size_t nwritten;
     gcry_mpi_t Ma;
     char *Ra_binary = NULL;
+    uint16_t uint16;
 
     *rbuflen = 0;
 
@@ -267,7 +268,8 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
 
     /* Session ID first */
     ID = dhxhash(obj);
-    *(uint16_t *)rbuf = htons(ID);
+    uint16 = htons(ID);
+    memcpy(rbuf, &uint16, sizeof(uint16_t));
     rbuf += 2;
     *rbuflen += 2;
 
@@ -281,7 +283,9 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     *rbuflen += 4;
 
     /* len = length of p = PRIMEBITS/8 */
-    *(uint16_t *)rbuf = htons((uint16_t) PRIMEBITS/8);
+
+    uint16 = htons((uint16_t) PRIMEBITS/8);
+    memcpy(rbuf, &uint16, sizeof(uint16_t));
     rbuf += 2;
     *rbuflen += 2;
 
@@ -403,6 +407,7 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
     char serverNonce_bin[16];
     gcry_cipher_hd_t ctx;
     gcry_error_t ctxerror;
+    uint16_t uint16;
 
     *rbuflen = 0;
 
@@ -488,7 +493,8 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
     /* ---- Start building reply packet ---- */
 
     /* Session ID + 1 first */
-    *(uint16_t *)rbuf = htons(ID+1);
+    uint16 = htons(ID+1);
+    memcpy(rbuf, &uint16, sizeof(uint16_t));
     rbuf += 2;
     *rbuflen += 2;
 
@@ -718,7 +724,8 @@ static int pam_logincont(void *obj, struct passwd **uam_pwd,
     int ret;
 
     /* check for session id */
-    retID = ntohs(*(uint16_t *)ibuf);
+    memcpy(&retID, ibuf, sizeof(uint16_t));
+    retID = ntohs(retID);
     if (retID == ID)
         ret = logincont1(obj, ibuf, ibuflen, rbuf, rbuflen);
     else if (retID == ID+1)
index 8d31b9f845b3502eb4935d38a0df5cf6635cfac2..c4a322ad48220ca899783ce5d0a83c17b4a4650c 100644 (file)
@@ -160,6 +160,7 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
 #ifdef SHADOWPW
     struct spwd *sp;
 #endif /* SHADOWPW */
+    uint16_t uint16;
 
     *rbuflen = 0;
 
@@ -209,7 +210,8 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
 
     /* Session ID first */
     ID = dhxhash(obj);
-    *(uint16_t *)rbuf = htons(ID);
+    uint16 = htons(ID);
+    memcpy(rbuf, &uint16, sizeof(uint16_t));
     rbuf += 2;
     *rbuflen += 2;
 
@@ -223,7 +225,8 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     *rbuflen += 4;
 
     /* len = length of p = PRIMEBITS/8 */
-    *(uint16_t *)rbuf = htons((uint16_t) PRIMEBITS/8);
+    uint16 = htons((uint16_t) PRIMEBITS/8);
+    memcpy(rbuf, &uint16, sizeof(uint16_t));
     rbuf += 2;
     *rbuflen += 2;
 
@@ -348,6 +351,7 @@ static int logincont1(void *obj _U_, struct passwd **uam_pwd _U_,
     char serverNonce_bin[16];
     gcry_cipher_hd_t ctx;
     gcry_error_t ctxerror;
+    uint16_t uint16;
 
     *rbuflen = 0;
 
@@ -435,7 +439,8 @@ static int logincont1(void *obj _U_, struct passwd **uam_pwd _U_,
     /* ---- Start building reply packet ---- */
 
     /* Session ID + 1 first */
-    *(uint16_t *)rbuf = htons(ID+1);
+    uint16 = htons(ID+1);
+    memcpy(rbuf, &uint16, sizeof(uint16_t));
     rbuf += 2;
     *rbuflen += 2;
 
@@ -586,7 +591,8 @@ static int passwd_logincont(void *obj, struct passwd **uam_pwd,
     int ret;
 
     /* check for session id */
-    retID = ntohs(*(uint16_t *)ibuf);
+    memcpy(&retID, ibuf, sizeof(uint16_t));
+    retID = ntohs(retID);
     if (retID == ID)
         ret = logincont1(obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen);
     else if (retID == ID+1)
index 7d6e7d620cf6ad0aaf554c814c9b0774e0ccc3d4..b71c13e689cd3cab889cbb6a24dfb7bbf1c45417 100644 (file)
@@ -229,6 +229,7 @@ int getnamefromuuid(const uuidp_t uuidp, char **name, uuidtype_t *type) {
     int ret;
     uid_t uid;
     gid_t gid;
+    uint32_t tmp;
     struct passwd *pwd;
     struct group *grp;
 
@@ -250,7 +251,8 @@ int getnamefromuuid(const uuidp_t uuidp, char **name, uuidtype_t *type) {
     /* Check if UUID is a client local one */
     if (memcmp(uuidp, local_user_uuid, 12) == 0) {
         *type = UUID_USER;
-        uid = ntohl(*(uint32_t *)(uuidp + 12));
+        memcpy(&tmp, uuidp + 12, sizeof(uint32_t));
+        uid = ntohl(tmp);
         if ((pwd = getpwuid(uid)) == NULL) {
             /* not found, add negative entry to cache */
             add_cachebyuuid(uuidp, "UUID_ENOENT", UUID_ENOENT, 0);
@@ -266,7 +268,8 @@ int getnamefromuuid(const uuidp_t uuidp, char **name, uuidtype_t *type) {
         return ret;
     } else if (memcmp(uuidp, local_group_uuid, 12) == 0) {
         *type = UUID_GROUP;
-        gid = ntohl(*(uint32_t *)(uuidp + 12));
+        memcpy(&tmp, uuidp + 12, sizeof(uint32_t));
+        gid = ntohl(tmp);
         if ((grp = getgrgid(gid)) == NULL) {
             /* not found, add negative entry to cache */
             add_cachebyuuid(uuidp, "UUID_ENOENT", UUID_ENOENT, 0);
index 0bee14153d234f2200f4da2b252087572dbf4566..016f92fb7878dbc065a09d76f10cff0632af86fa 100644 (file)
@@ -124,26 +124,30 @@ static int unpack_header(struct ea * restrict ea)
 {
     int ret = 0;
     unsigned int count = 0;
+    uint16_t uint16;
     uint32_t uint32;
     char *buf;
 
     /* Check magic and version */
     buf = ea->ea_data;
-    if (*(uint32_t *)buf != htonl(EA_MAGIC)) {
-        LOG(log_error, logtype_afpd, "unpack_header: wrong magic 0x%08x", *(uint32_t *)buf);
+    memcpy(&uint32, buf, sizeof(uint32_t));
+    if (uint32 != htonl(EA_MAGIC)) {
+        LOG(log_error, logtype_afpd, "unpack_header: wrong magic 0x%08x", uint32);
         ret = -1;
         goto exit;
     }
     buf += 4;
-    if (*(uint16_t *)buf != htons(EA_VERSION)) {
-        LOG(log_error, logtype_afpd, "unpack_header: wrong version 0x%04x", *(uint16_t *)buf);
+    memcpy(&uint16, buf, sizeof(uint16_t));
+    if (uint16 != htons(EA_VERSION)) {
+        LOG(log_error, logtype_afpd, "unpack_header: wrong version 0x%04x", uint16);
         ret = -1;
         goto exit;
     }
     buf += 2;
 
     /* Get EA count */
-    ea->ea_count = ntohs(*(uint16_t *)buf);
+    memcpy(&uint16, buf, sizeof(uint16_t));
+    ea->ea_count = ntohs(uint16);
     LOG(log_debug, logtype_afpd, "unpack_header: number of EAs: %u", ea->ea_count);
     buf += 2;
 
@@ -391,6 +395,8 @@ static int create_ea_header(const char * restrict uname,
 {
     int fd = -1, err = 0;
     char *ptr;
+    uint16_t uint16;
+    uint32_t uint32;
 
     if ((fd = open(uname, O_RDWR | O_CREAT | O_EXCL, 0666 & ~ea->vol->v_umask)) == -1) {
         LOG(log_error, logtype_afpd, "ea_create: open race condition with ea header for file: %s", uname);
@@ -406,11 +412,15 @@ static int create_ea_header(const char * restrict uname,
 
     /* Now init it */
     ptr = ea->ea_data;
-    *(uint32_t *)ptr = htonl(EA_MAGIC);
+    uint32 = htonl(EA_MAGIC);
+    memcpy(ptr, &uint32, sizeof(uint32_t));
     ptr += EA_MAGIC_LEN;
-    *(uint16_t *)ptr = htons(EA_VERSION);
+
+    uint16 = htons(EA_VERSION);
+    memcpy(ptr, &uint16, sizeof(uint16_t));
     ptr += EA_VERSION_LEN;
-    *(uint16_t *)ptr = 0;       /* count */
+
+    memset(ptr, 0, 2);          /* count */
 
     ea->ea_size = EA_HEADER_SIZE;
     ea->ea_inited = EA_INITED;