@@ -1789,7 +1789,7 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
*/
if (path_extra_1) {
size_t full_len = path_extra_1len + 1 + pathlen - strip_slash;
- size_t partial_len = pathlen - 1 - strip_slash;
+ size_t partial_len = pathlen - strip_slash;
if (path_extra_2) {
full_len += path_extra_2len + 1;
}
@@ -1804,12 +1804,17 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
return 0;
}
}
- memcpy(alloced_path, path, partial_len);
- alloced_path[partial_len] = '\0';
- memcpy(alloced_path + partial_len + 1, path_extra_1, path_extra_1len);
- alloced_path[partial_len + path_extra_1len + 1] = '\0';
+ if (pathlen) {
+ memcpy(alloced_path, path, partial_len - 1);
+ alloced_path[partial_len - 1] = '\0';
+ } else {
+ alloced_path[0] = '\0';
+ partial_len = 1;
+ }
+ memcpy(alloced_path + partial_len, path_extra_1, path_extra_1len);
+ alloced_path[partial_len + path_extra_1len] = '\0';
if (path_extra_2) {
- memcpy(alloced_path + partial_len + path_extra_1len + 2, path_extra_2, path_extra_2len);
+ memcpy(alloced_path + partial_len + path_extra_1len + 1, path_extra_2, path_extra_2len);
}
alloced_path[full_len - 1] = '\0';
path = alloced_path;
On Fedora45, we can end up in a situation where path_extra_1 (for xattr/rename ops) but path is of zero length. The path_extra_1 codepath does not handle this well and corrupts memory. The issue is "partial_len = pathlen - 1 - strip_slash" when pathlen is 0 (and hence strip_slash is also 0). This leads to invalid memory writes and if those happen to access off the end of a mapped segment, the program segfaults. Fix the code to handle the pathlen=0 case. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> --- pseudo_client.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)