From 4236badf30da3ebff007ad72d91fd10e32f5c345 Mon Sep 17 00:00:00 2001 From: Martin Ebourne Date: Fri, 6 Jan 2006 16:23:32 +0000 Subject: 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. --- lib/backupclient/BackupClientFileAttributes.cpp | 5 ++++- test/bbackupd/testbbackupd.cpp | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 70c0d09d..a31cd7b4 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -511,6 +511,10 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc // 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 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc // 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); diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 72917978..0e01619a 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -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 @@ bool write_xattr_test(const char *filename, const char *attrName, unsigned int l } 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 @@ int test_basics() #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 @@ int test_basics() 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 @@ int test_basics() // 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 @@ int test_basics() 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)); } -- cgit v1.2.3