Index: trunk/src/VBox/Additions/WINNT/SharedFolders/driver/info.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/SharedFolders/driver/info.c	(revision 40272)
+++ trunk/src/VBox/Additions/WINNT/SharedFolders/driver/info.c	(revision 40278)
@@ -539,4 +539,5 @@
     ULONG cbInfoBuffer = RxContext->Info.LengthRemaining;
     ULONG cbToCopy = 0;
+    ULONG cbString = 0;
 
     Log(("VBOXSF: MrxQueryVolumeInfo: pInfoBuffer = %p, cbInfoBuffer = %d\n",
@@ -578,10 +579,15 @@
             pRootName++; /* Remove the leading backslash. */
 
-            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsVolumeInformation: Root name = %.*ls\n",
-                 cbRootName / sizeof(WCHAR), pRootName));
-
-            cbToCopy = sizeof(FILE_FS_VOLUME_INFORMATION);
-            cbToCopy += VBOX_VOLNAME_PREFIX_SIZE;
-            cbToCopy += cbRootName;
+            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsVolumeInformation: Root name = %.*ls, %d bytes\n",
+                 cbRootName / sizeof(WCHAR), pRootName, cbRootName));
+
+            cbToCopy = FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel);
+
+            cbString  = VBOX_VOLNAME_PREFIX_SIZE;
+            cbString += cbRootName;
+            cbString += sizeof(WCHAR);
+
+            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsVolumeInformation: cbToCopy %d, cbString %d\n",
+                 cbToCopy, cbString));
 
             if (cbInfoBuffer < cbToCopy)
@@ -591,5 +597,5 @@
             }
 
-            RtlZeroMemory(pInfo, sizeof(FILE_FS_VOLUME_INFORMATION));
+            RtlZeroMemory(pInfo, cbToCopy);
 
             /* Query serial number. */
@@ -617,9 +623,35 @@
 
             pInfo->VolumeCreationTime.QuadPart = 0;
-            pInfo->VolumeLabelLength = VBOX_VOLNAME_PREFIX_SIZE + cbRootName;
             pInfo->SupportsObjects = FALSE;
 
-            RtlCopyMemory(&pInfo->VolumeLabel[0], VBOX_VOLNAME_PREFIX, VBOX_VOLNAME_PREFIX_SIZE);
-            RtlCopyMemory(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)], pRootName, cbRootName);
+            if (cbInfoBuffer >= cbToCopy + cbString)
+            {
+                RtlCopyMemory(&pInfo->VolumeLabel[0],
+                              VBOX_VOLNAME_PREFIX,
+                              VBOX_VOLNAME_PREFIX_SIZE);
+                RtlCopyMemory(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)],
+                              pRootName,
+                              cbRootName);
+                pInfo->VolumeLabel[cbString / sizeof(WCHAR) -  1] = 0;
+            }
+            else
+            {
+                cbString = cbInfoBuffer - cbToCopy;
+
+                RtlCopyMemory(&pInfo->VolumeLabel[0],
+                              VBOX_VOLNAME_PREFIX,
+                              RT_MIN(cbString, VBOX_VOLNAME_PREFIX_SIZE));
+                if (cbString > VBOX_VOLNAME_PREFIX_SIZE)
+                {
+                    RtlCopyMemory(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)],
+                                  pRootName,
+                                  cbString - VBOX_VOLNAME_PREFIX_SIZE);
+                }
+            }
+
+            pInfo->VolumeLabelLength = cbString;
+
+            cbToCopy += cbString;
+
             Log(("VBOXSF: MrxQueryVolumeInfo: FileFsVolumeInformation: VolumeLabelLength %d\n",
                  pInfo->VolumeLabelLength));
@@ -646,10 +678,12 @@
             pRootName++; /* Remove the leading backslash. */
 
-            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsLabelInformation: Root name = %.*ls\n",
-                 cbRootName / sizeof(WCHAR), pRootName));
-
-            cbToCopy = sizeof(FILE_FS_LABEL_INFORMATION);
-            cbToCopy += VBOX_VOLNAME_PREFIX_SIZE;
-            cbToCopy += cbRootName;
+            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsLabelInformation: Root name = %.*ls, %d bytes\n",
+                 cbRootName / sizeof(WCHAR), pRootName, cbRootName));
+
+            cbToCopy = FIELD_OFFSET(FILE_FS_LABEL_INFORMATION, VolumeLabel);
+
+            cbString  = VBOX_VOLNAME_PREFIX_SIZE;
+            cbString += cbRootName;
+            cbString += sizeof(WCHAR);
 
             if (cbInfoBuffer < cbToCopy)
@@ -659,10 +693,37 @@
             }
 
-            RtlZeroMemory(pInfo, sizeof(FILE_FS_LABEL_INFORMATION));
-
-            pInfo->VolumeLabelLength = VBOX_VOLNAME_PREFIX_SIZE + cbRootName;
-
-            RtlCopyMemory(&pInfo->VolumeLabel[0], VBOX_VOLNAME_PREFIX, VBOX_VOLNAME_PREFIX_SIZE);
-            RtlCopyMemory(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)], pRootName, cbRootName);
+            RtlZeroMemory(pInfo, cbToCopy);
+
+            if (cbInfoBuffer >= cbToCopy + cbString)
+            {
+                RtlCopyMemory(&pInfo->VolumeLabel[0],
+                              VBOX_VOLNAME_PREFIX,
+                              VBOX_VOLNAME_PREFIX_SIZE);
+                RtlCopyMemory(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)],
+                              pRootName,
+                              cbRootName);
+                pInfo->VolumeLabel[cbString / sizeof(WCHAR) -  1] = 0;
+            }
+            else
+            {
+                cbString = cbInfoBuffer - cbToCopy;
+
+                RtlCopyMemory(&pInfo->VolumeLabel[0],
+                              VBOX_VOLNAME_PREFIX,
+                              RT_MIN(cbString, VBOX_VOLNAME_PREFIX_SIZE));
+                if (cbString > VBOX_VOLNAME_PREFIX_SIZE)
+                {
+                    RtlCopyMemory(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)],
+                                  pRootName,
+                                  cbString - VBOX_VOLNAME_PREFIX_SIZE);
+                }
+            }
+
+            pInfo->VolumeLabelLength = cbString;
+
+            cbToCopy += cbString;
+
+            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsLabelInformation: VolumeLabelLength %d\n",
+                 pInfo->VolumeLabelLength));
 
             Status = STATUS_SUCCESS;
@@ -789,10 +850,11 @@
         case FileFsAttributeInformation:
         {
-            PFILE_FS_ATTRIBUTE_INFORMATION pAttribInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)pInfoBuffer;
+            PFILE_FS_ATTRIBUTE_INFORMATION pInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)pInfoBuffer;
 
             Log(("VBOXSF: MrxQueryVolumeInfo: FileFsAttributeInformation\n"));
 
-            cbToCopy = sizeof(FILE_FS_ATTRIBUTE_INFORMATION);
-            cbToCopy += sizeof(MRX_VBOX_FILESYS_NAME_U) - sizeof(WCHAR);
+            cbToCopy = FIELD_OFFSET(FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName);
+
+            cbString = sizeof(MRX_VBOX_FILESYS_NAME_U);
 
             if (cbInfoBuffer < cbToCopy)
@@ -802,8 +864,28 @@
             }
 
-            pAttribInfo->FileSystemAttributes = 0; /** @todo set unicode, case sensitive etc? */
-            pAttribInfo->MaximumComponentNameLength = 255; /** @todo should query from the host */
-            pAttribInfo->FileSystemNameLength = sizeof(MRX_VBOX_FILESYS_NAME_U);
-            RtlCopyMemory(pAttribInfo->FileSystemName, MRX_VBOX_FILESYS_NAME_U, sizeof(MRX_VBOX_FILESYS_NAME_U));
+            pInfo->FileSystemAttributes = 0; /** @todo set unicode, case sensitive etc? */
+            pInfo->MaximumComponentNameLength = 255; /** @todo should query from the host */
+
+            if (cbInfoBuffer >= cbToCopy + cbString)
+            {
+                RtlCopyMemory(pInfo->FileSystemName,
+                              MRX_VBOX_FILESYS_NAME_U,
+                              sizeof(MRX_VBOX_FILESYS_NAME_U));
+            }
+            else
+            {
+                cbString = cbInfoBuffer - cbToCopy;
+
+                RtlCopyMemory(pInfo->FileSystemName,
+                              MRX_VBOX_FILESYS_NAME_U,
+                              RT_MIN(cbString, sizeof(MRX_VBOX_FILESYS_NAME_U)));
+            }
+
+            pInfo->FileSystemNameLength = cbString;
+
+            cbToCopy += cbString;
+
+            Log(("VBOXSF: MrxQueryVolumeInfo: FileFsAttributeInformation: FileSystemNameLength %d\n",
+                 pInfo->FileSystemNameLength));
 
             Status = STATUS_SUCCESS;
