smbfs: Add default value for statvfs.f_namemax
libsmbclient returns 0 for the statvfs.f_namemax (maximum filename
length) element, which causes explicit length checks, such as those
performed in the chrome.fileManagerPrivate API, to fail. This is a
forward-compatible fix: iff the value is 0, it is replaced with a
default that is consistent across most target filesystems (ie. NTFS,
ext3, ext4).
BUG=chromium:1072893
TEST=Manually tested by renaming a file and a directory
Change-Id: I6cbdaf544266f9d674df2f80d17f2bc3c363a7d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2172100
Tested-by: Josh Simmons <simmonsjosh@google.com>
Commit-Queue: Josh Simmons <simmonsjosh@google.com>
Reviewed-by: Anand Mistry <amistry@chromium.org>
diff --git a/smbfs/samba_interface_impl.cc b/smbfs/samba_interface_impl.cc
index 62a2dce..19e7338 100644
--- a/smbfs/samba_interface_impl.cc
+++ b/smbfs/samba_interface_impl.cc
@@ -17,6 +17,9 @@
namespace {
+// Default that is consistent with common filesystems (ie. ext3, ext4, NFTS).
+constexpr int kMaxShareFilenameLength = 255;
+
void SambaLog(void* private_ptr, int level, const char* msg) {
VLOG(level) << "libsmbclient: " << msg;
}
@@ -150,6 +153,11 @@
out_statvfs->f_frsize *= out_statvfs->f_bsize;
}
+ // libsmbclient can return 0 for this but some clients require it to be set.
+ if (!out_statvfs->f_namemax) {
+ out_statvfs->f_namemax = kMaxShareFilenameLength;
+ }
+
return 0;
}