From 617ebc89f81c923f65a77def056525b381f5d07e Mon Sep 17 00:00:00 2001 From: xuchenchen Date: Fri, 31 Oct 2025 16:19:26 +0800 Subject: [PATCH] Fix: Correct initialization of size_t variable to avoid overflow In the functions `glfs_anonymous_pwritev` and `iobuf_copy`, the `size_t` variable `size` was incorrectly initialized to `-1`, causing an overflow when assigned to a `size_t` (an unsigned type). This commit updates the initialization to `0`, ensuring proper handling of size values and preventing potential bugs related to the overflow. Signed-off-by: xuchenchen --- api/src/glfs-fops.c | 2 +- libglusterfs/src/iobuf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index c9e22d10fbe..d56e5fa10da 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -6323,7 +6323,7 @@ glfs_anonymous_pwritev(struct glfs *fs, struct glfs_object *object, inode_t *inode = NULL; fd_t *fd = NULL; int ret = -1; - size_t size = -1; + size_t size = 0; DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index 2d765a0d60f..eb453021dc5 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -981,7 +981,7 @@ iobuf_copy(struct iobuf_pool *iobuf_pool, const struct iovec *iovec_src, int iovcnt, struct iobref **iobref, struct iobuf **iobuf, struct iovec *iov_dst) { - size_t size = -1; + size_t size = 0; int ret = 0; size = iov_length(iovec_src, iovcnt);