Cygwin: use new XATTR_{NAME,SIZE}_MAX instead of MAX_EA_{NAME,VALUE}_LEN

Signed-off-by: Philippe Cerfon <philcerf@gmail.com>
This commit is contained in:
Philippe Cerfon 2023-06-06 02:52:49 +02:00 committed by Corinna Vinschen
parent 538b29a8da
commit 0480315010
1 changed files with 11 additions and 9 deletions

View File

@ -17,9 +17,11 @@ details. */
#include "tls_pbuf.h" #include "tls_pbuf.h"
#include <stdlib.h> #include <stdlib.h>
#include <attr/xattr.h> #include <attr/xattr.h>
#include <cygwin/limits.h>
#define MAX_EA_NAME_LEN 256 /* On storage the `user.` prefix is not included but the terminating null byte
#define MAX_EA_VALUE_LEN 65536 is needed.*/
#define _XATTR_NAME_MAX_ONDISK_ (XATTR_NAME_MAX - strlen("user.") + 1)
/* At least one maximum sized entry fits. /* At least one maximum sized entry fits.
CV 2014-04-04: NtQueryEaFile function chokes on buffers bigger than 64K CV 2014-04-04: NtQueryEaFile function chokes on buffers bigger than 64K
@ -27,13 +29,13 @@ details. */
on a remote share, at least on Windows 7 and later. on a remote share, at least on Windows 7 and later.
In theory the buffer should have a size of In theory the buffer should have a size of
sizeof (FILE_FULL_EA_INFORMATION) + MAX_EA_NAME_LEN sizeof (FILE_FULL_EA_INFORMATION) + _XATTR_NAME_MAX_ONDISK_
+ MAX_EA_VALUE_LEN + XATTR_SIZE_MAX
(65804 bytes), but we're opting for simplicity here, and (65804 bytes), but we're opting for simplicity here, and
a 64K buffer has the advantage that we can use a tmp_pathbuf a 64K buffer has the advantage that we can use a tmp_pathbuf
buffer, rather than having to alloca 64K from stack. */ buffer, rather than having to alloca 64K from stack. */
#define EA_BUFSIZ MAX_EA_VALUE_LEN #define EA_BUFSIZ XATTR_SIZE_MAX
#define NEXT_FEA(p) ((PFILE_FULL_EA_INFORMATION) (p->NextEntryOffset \ #define NEXT_FEA(p) ((PFILE_FULL_EA_INFORMATION) (p->NextEntryOffset \
? (char *) p + p->NextEntryOffset : NULL)) ? (char *) p + p->NextEntryOffset : NULL))
@ -55,7 +57,7 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size)
returns the last EA entry of the file infinitely. Even utilizing the returns the last EA entry of the file infinitely. Even utilizing the
optional EaIndex only helps marginally. If you use that, the last optional EaIndex only helps marginally. If you use that, the last
EA in the file is returned twice. */ EA in the file is returned twice. */
char lastname[MAX_EA_NAME_LEN]; char lastname[_XATTR_NAME_MAX_ONDISK_];
__try __try
{ {
@ -95,7 +97,7 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size)
__leave; __leave;
} }
if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN) if ((nlen = strlen (name)) >= _XATTR_NAME_MAX_ONDISK_)
{ {
set_errno (EINVAL); set_errno (EINVAL);
__leave; __leave;
@ -197,7 +199,7 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size)
/* For compatibility with Linux, we always prepend "user." to /* For compatibility with Linux, we always prepend "user." to
the attribute name, so effectively we only support user the attribute name, so effectively we only support user
attributes from a application point of view. */ attributes from a application point of view. */
char tmpbuf[MAX_EA_NAME_LEN * 2]; char tmpbuf[_XATTR_NAME_MAX_ONDISK_ * 2];
char *tp = stpcpy (tmpbuf, "user."); char *tp = stpcpy (tmpbuf, "user.");
stpcpy (tp, fea->EaName); stpcpy (tp, fea->EaName);
/* NTFS stores all EA names in uppercase unfortunately. To /* NTFS stores all EA names in uppercase unfortunately. To
@ -297,7 +299,7 @@ write_ea (HANDLE hdl, path_conv &pc, const char *name, const char *value,
/* Skip "user." prefix. */ /* Skip "user." prefix. */
name += 5; name += 5;
if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN) if ((nlen = strlen (name)) >= _XATTR_NAME_MAX_ONDISK_)
{ {
set_errno (EINVAL); set_errno (EINVAL);
__leave; __leave;