erofs-utils: s3: fix memory leak in s3erofs_create_object_iterator
PATCH 1/1 erofs-utils: s3: fix memory leak in s3erofs_create_object_iterator
In s3erofs_create_object_iterator(), if the parsed prefix length exceeds S3EROFS_PATH_MAX, the function aborts and returns an -EINVAL error pointer. However, the 'iter' structure was already allocated via calloc() and left unfreed, causing a memory leak.
This commit adds the missing free(iter) call in the error path to prevent leaking memory when excessively long S3 bucket paths are provided.
--- lib/remotes/s3.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/remotes/s3.c +3 -1
@@ -911,8 +911,10 @@ s3erofs_create_object_iterator(struct erofs_s3 *s3, const char *path, iter->bucket =NULL ; iter->prefix =strdup (path +1 ); }else { -if (++prefix - path >S3EROFS_PATH_MAX ) +if (++prefix - path >S3EROFS_PATH_MAX ){ +free (iter);return ERR_PTR (-EINVAL ); + } iter->bucket =strndup (path, prefix - path); iter->prefix =strdup (prefix); }
Signature · 1 line
2.52.0
Quoted 19 lines · Nithurshen
In
s3erofs_create_object_iterator(), if the parsed prefix length exceedsS3EROFS_PATH_MAX, the function aborts and returns an-EINVALerror pointer. However, the 'iter' structure was already allocated viacalloc()and left unfreed, causing a memory leak.This commit adds the missing free(iter) call in the error path to prevent leaking memory when excessively long S3 bucket paths are provided.
Signed-off-by Nithurshen <[email protected]>--- lib/remotes/s3.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/remotes/s3.c +0
-0
lib/remotes/s3.c s3erofs_create_object_iterator(struct erofs_s3 *s3, const char *path, · line 914
Quoted 5 lines
lib/remotes/s3.c +1
-1@@ -911,8 +911,10 @@ s3erofs_create_object_iterator(struct erofs_s3 *s3, const char *path, iter->bucket =NULL ; iter->prefix =strdup (path +1 ); }else { -if (++prefix - path >S3EROFS_PATH_MAX ) +if (++prefix - path >S3EROFS_PATH_MAX ){
missing a space before the brace, otherwise LGTM.
Quoted 6 lines
lib/remotes/s3.c +2
-0+free (iter);return ERR_PTR (-EINVAL ); + } iter->bucket =strndup (path, prefix - path); iter->prefix =strdup (prefix); }
PATCH v2 1/1 erofs-utils: s3: fix memory leak in s3erofs_create_object_iterator
In reply to NithurshenIn s3erofs_create_object_iterator(), if the parsed prefix length exceeds S3EROFS_PATH_MAX, the function aborts and returns an -EINVAL error pointer. However, the 'iter' structure was already allocated via calloc() and left unfreed, causing a memory leak.
This commit adds the missing free(iter) call in the error path to prevent leaking memory when excessively long S3 bucket paths are provided.
--- lib/remotes/s3.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/remotes/s3.c +3 -1
@@ -911,8 +911,10 @@ s3erofs_create_object_iterator(struct erofs_s3 *s3, const char *path, iter->bucket =NULL ; iter->prefix =strdup (path +1 ); }else { -if (++prefix - path >S3EROFS_PATH_MAX ) +if (++prefix - path >S3EROFS_PATH_MAX ) { +free (iter);return ERR_PTR (-EINVAL ); + } iter->bucket =strndup (path, prefix - path); iter->prefix =strdup (prefix); }
Signature · 1 line
2.52.0