summaryrefslogtreecommitdiff
path: root/libattr
diff options
context:
space:
mode:
Diffstat (limited to 'libattr')
-rw-r--r--libattr/solaris.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/libattr/solaris.c b/libattr/solaris.c
index 966a977..f5e4426 100644
--- a/libattr/solaris.c
+++ b/libattr/solaris.c
@@ -91,9 +91,21 @@ __fflistxattr (int xfd, char *list, size_t size)
DIR *d;
struct dirent *de;
size_t l;
-
+/*
+ * The fdopendir() function opens a directory stream for the
+ * directory file descriptor "xfd". The directory file
+ * descriptor should not be used or closed following a successful
+ * function call.
+ * ...
+ * The closedir() function closes the directory stream referred
+ * to by the argument "d". Upon return, the value of dirp may
+ * no longer point to an accessible object of the type DIR. If
+ * a file descriptor is used to implement type DIR, that file
+ * descriptor will be closed.
+ */
d = fdopendir(xfd);
if (d == NULL) {
+ (void) close(xfd);
return (-1);
}
@@ -112,7 +124,11 @@ __fflistxattr (int xfd, char *list, size_t size)
/* Define __EXTENSIONS__ for strlcpy() */
/* http://www.gratisoft.us/todd/papers/strlcpy.html */
l = strlcpy(list, de->d_name, size);
- if (l >= size) {
+
+ /* if size == 0 we effectively calculate the size of
+ * a buffer which is sufficiently large to hold the list of names
+ */
+ if ((l >= size) && (size > 0)) {
errno = ERANGE;
rv = -1;
break;
@@ -140,7 +156,7 @@ flistxattr (int fd, char *list, size_t size)
rv = __fflistxattr(xfd, list, size);
- (void) close(xfd);
+ /* xfd is closed on __fflistxattr() */
return (rv);
}
@@ -157,7 +173,7 @@ listxattr (const char * path, char *list, size_t size)
rv = __fflistxattr(xfd, list, size);
- (void) close(xfd);
+ /* xfd is closed on __fflistxattr() */
return (rv);
}