exofs: don't increase urilen if krealloc() fails
PATCH 1/1 exofs: don't increase urilen if krealloc() fails
Without the patch, edp->urilen is increased before krealloc(). If krealloc() fails, edp->urilen is too high. Fix that by only updating edp->urilen if krealloc() is successful.
Signed-off-by Zhao Hongjiang <[email protected]>
--- fs/exofs/sys.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/exofs/sys.c +2 -2
@@ -82,11 +82,11 @@ static ssize_t uri_store(struct exofs_dev *edp, const char *buf, size_t len) {uint8_t *new_uri; - edp->urilen =strlen (buf) +1 ; - new_uri =krealloc (edp->uri, edp->urilen,GFP_KERNEL ); + new_uri =krealloc (edp->uri,strlen (buf) +1 ,GFP_KERNEL );if (new_uri ==NULL )return -ENOMEM ; edp->uri = new_uri; + edp->urilen =strlen (buf) +1 ;strncpy (edp->uri, buf, edp->urilen);return edp->urilen; }
-- 1.7.1
Quoted 18 lines · Zhao Hongjiang
Without the patch,
edp->urilenis increased beforekrealloc(). Ifkrealloc()fails,edp->urilenis too high. Fix that by only updatingedp->urilenifkrealloc()is successful.Signed-off-by Zhao Hongjiang <[email protected]>--- fs/exofs/sys.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)fs/exofs/sys.c +0
-1@@ -82,11 +82,11 @@ static ssize_t uri_store(struct exofs_dev *edp, const char *buf, size_t len) {uint8_t *new_uri; - edp->urilen =strlen (buf) +1 ;
fs/exofs/sys.c static ssize_t uri_store(struct exofs_dev *edp, const char *buf, size_t len)
Quoted 10 lines
fs/exofs/sys.c +2
-2- new_uri =krealloc (edp->uri, edp->urilen,GFP_KERNEL ); + new_uri =krealloc (edp->uri,strlen (buf) +1 ,GFP_KERNEL );if (new_uri ==NULL )return -ENOMEM ; edp->uri = new_uri; + edp->urilen =strlen (buf) +1 ;strncpy (edp->uri, buf, edp->urilen);return edp->urilen; } -- 1.7.1
Thank you, will apply
Boaz