[Box Backup-dev] COMMIT r302 - in box/trunk: lib/backupclient test/bbackupd

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Fri, 6 Jan 2006 16:23:34 +0000 (GMT)


Author: martin
Date: 2006-01-06 16:23:32 +0000 (Fri, 06 Jan 2006)
New Revision: 302

Modified:
   box/trunk/lib/backupclient/BackupClientFileAttributes.cpp
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Fixes for xattr on Linux

- A very unlikely failure where getxattr returns an error code the first time
  but succeeds the second time could cause buffer overrun and corruption.

Affecting the tests only:

- On Linux (and presumably Irix) normal users can only modify attributes in
  the 'user.' namespace.
- Some filesystems can have strict limits on value size (eg. 1024 bytes on
  ext3 depending on block size)
- ENOATTR is defined in xattr/xattr.h. This file is an optional install and is
  not needed for the rest of box to use extended attributes. Provide it
  ourselves if not present.


Modified: box/trunk/lib/backupclient/BackupClientFileAttributes.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupClientFileAttributes.cpp	2006-01-06 10:28:03 UTC (rev 301)
+++ box/trunk/lib/backupclient/BackupClientFileAttributes.cpp	2006-01-06 16:23:32 UTC (rev 302)
@@ -511,6 +511,10 @@
 				// Find size of attribute (must call with buffer and length 0 on some platforms,
 				// as -1 is returned if the data doesn't fit.)
 				int valueSize = ::lgetxattr(Filename, attrKey.c_str(), 0, 0);
+				if(valueSize<0)
+				{
+					THROW_EXCEPTION(CommonException, OSFileError);
+				}
 
 				// Resize block, if needed
 				if(xattrSize+valueSize>xattrBufferSize)
@@ -522,7 +526,6 @@
 
 				// This gets the attribute value (may be text or binary), no termination
 				valueSize = ::lgetxattr(Filename, attrKey.c_str(), buffer+xattrSize, xattrBufferSize-xattrSize);
-
 				if(valueSize<0)
 				{
 					THROW_EXCEPTION(CommonException, OSFileError);

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2006-01-06 10:28:03 UTC (rev 301)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2006-01-06 16:23:32 UTC (rev 302)
@@ -44,6 +44,11 @@
 
 #include "MemLeakFindOn.h"
 
+// ENOATTR may be defined in a separate header file which we may not have
+#ifndef ENOATTR
+#define ENOATTR ENODATA
+#endif
+
 // two cycles and a bit
 #define TIME_TO_WAIT_FOR_BACKUP_OPERATION	12
 
@@ -194,7 +199,7 @@
 	}
 	else
 	{
-		char data[4096];
+		char data[1024];
 		if(length > sizeof(data)) length = sizeof(data);
 		
 		if(::fread(data, length, 1, xattrTestDataHandle) != 1)
@@ -327,7 +332,7 @@
 #ifdef HAVE_SYS_XATTR_H
 	// Write some attributes to the file, checking for ENOTSUP
 	bool xattrNotSupported = false;
-	if(!write_xattr_test("testfiles/test1", "attr_1", 1276, &xattrNotSupported) && xattrNotSupported)
+	if(!write_xattr_test("testfiles/test1", "user.attr_1", 1000, &xattrNotSupported) && xattrNotSupported)
 	{
 		::printf("***********\nYour platform supports xattr, but your filesystem does not.\nSkipping tests.\n***********\n");
 	}
@@ -336,8 +341,8 @@
 		BackupClientFileAttributes x1, x2, x3, x4;
 
 		// Write more attributes
-		TEST_THAT(write_xattr_test("testfiles/test1", "attr_2", 3427));
-		TEST_THAT(write_xattr_test("testfiles/test1", "sadfohij39998.3hj", 123));
+		TEST_THAT(write_xattr_test("testfiles/test1", "user.attr_2", 947));
+		TEST_THAT(write_xattr_test("testfiles/test1", "user.sadfohij39998.3hj", 123));
 	
 		// Read file attributes
 		x1.ReadAttributes("testfiles/test1");
@@ -352,7 +357,7 @@
 		
 		// Add more attributes to a file
 		x2.ReadAttributes("testfiles/test1");
-		TEST_THAT(write_xattr_test("testfiles/test1", "328989sj..sdf", 23));
+		TEST_THAT(write_xattr_test("testfiles/test1", "user.328989sj..sdf", 23));
 		
 		// Read them again, and check that the Compare() function detects that they're different
 		x3.ReadAttributes("testfiles/test1");
@@ -360,7 +365,7 @@
 		TEST_THAT(!x1.Compare(x3, true, true));
 		
 		// Change the value of one of them, leaving the size the same.
-		TEST_THAT(write_xattr_test("testfiles/test1", "328989sj..sdf", 23));
+		TEST_THAT(write_xattr_test("testfiles/test1", "user.328989sj..sdf", 23));
 		x4.ReadAttributes("testfiles/test1");
 		TEST_THAT(!x1.Compare(x4, true, true));
 	}