summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@linbit.com>2014-07-08 00:15:19 +0200
committerAndreas Gruenbacher <agruen@linbit.com>2014-07-08 00:33:24 +0200
commit7b6a70e22f42f57f6c04bfb414096fb702e24255 (patch)
tree92bd6f82ee0a9096ff25c03a509a585e8a09e700
parent59e0b9c9cf07b851f3b19c81314fb984854b7aa8 (diff)
downloadattr-7b6a70e22f42f57f6c04bfb414096fb702e24255.tar.gz
attr_list / attr_listf: Fix cursor off-by-one error
When an attribute cannot be added to the buffer in attr_list() or attr_listf(), we need to retry adding the same attribute on the next attempt, except when we didn't make progress. Reported-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
-rw-r--r--libattr/libattr.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libattr/libattr.c b/libattr/libattr.c
index 35bd877..e68d3f6 100644
--- a/libattr/libattr.c
+++ b/libattr/libattr.c
@@ -317,7 +317,11 @@ attr_list(const char *path, char *buffer, const int buffersize, int flags,
continue;
if (attr_list_pack(name, vlength, buffer, buffersize,
&start_offset, &end_offset)) {
- cursor->opaque[0] = count;
+ if (cursor->opaque[0] == count - 1) {
+ errno = EINVAL;
+ return -1;
+ }
+ cursor->opaque[0] = count - 1;
break;
}
}
@@ -357,7 +361,11 @@ attr_listf(int fd, char *buffer, const int buffersize, int flags,
continue;
if (attr_list_pack(name, vlength, buffer, buffersize,
&start_offset, &end_offset)) {
- cursor->opaque[0] = count;
+ if (cursor->opaque[0] == count - 1) {
+ errno = EINVAL;
+ return -1;
+ }
+ cursor->opaque[0] = count - 1;
break;
}
}