Fix for bug 7755 - SMBC_getdents_ctx() ignores struct alignment rules
authorJeremy Allison <jra@samba.org>
Wed, 27 Oct 2010 21:17:46 +0000 (14:17 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 27 Oct 2010 22:02:11 +0000 (22:02 +0000)
Based on a fix from Sven Neumann <s.neumann@raumfeld.com>.

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Wed Oct 27 22:02:11 UTC 2010 on sn-devel-104

source3/libsmb/libsmb_dir.c

index 7661ecf2f8a6250eda414cb07d86c9d8c5a3f899..9398f92612fe86897de5e88066e81cc2ec89144d 100644 (file)
@@ -1050,6 +1050,7 @@ SMBC_getdents_ctx(SMBCCTX *context,
 
        while ((dirlist = dir->dir_next)) {
                struct smbc_dirent *dirent;
+               struct smbc_dirent *currentEntry = (struct smbc_dirent *)ndir;
 
                if (!dirlist->dirent) {
 
@@ -1086,17 +1087,23 @@ SMBC_getdents_ctx(SMBCCTX *context,
 
                }
 
-               memcpy(ndir, dirent, reqd); /* Copy the data in ... */
+               memcpy(currentEntry, dirent, reqd); /* Copy the data in ... */
 
-               ((struct smbc_dirent *)ndir)->comment =
-                       (char *)(&((struct smbc_dirent *)ndir)->name +
-                                 dirent->namelen +
-                                 1);
+               currentEntry->comment = &currentEntry->name[0] +
+                                               dirent->namelen + 1;
 
                ndir += reqd;
-
                rem -= reqd;
 
+               /* Try and align the struct for the next entry
+                  on a valid pointer boundary by appending zeros */
+               while((rem > 0) && ((unsigned long long)ndir & (sizeof(void*) - 1))) {
+                       *ndir = '\0';
+                       rem--;
+                       ndir++;
+                       currentEntry->dirlen++;
+               }
+
                dir->dir_next = dirlist = dirlist -> next;
        }