Mini-OS: fix 9pfs frontend error path
PATCH 1/1 Mini-OS: fix 9pfs frontend error path
The early error exit in p9_stat() returns without zeroing the p9_stat buffer, resulting in free() being called with an uninitialized pointer.
Fix that by doing the zeroing first.
--- 9pfront.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
9pfront.c +2 -1
@@ -716,10 +716,11 @@ static int p9_stat(struct dev_9pfs *dev, uint32_t fid, struct p9_stat *stat)uint16_t total;int ret; +memset (stat,0 ,sizeof (*stat)); +if ( !req )return EAGAIN ; -memset (stat,0 ,sizeof (*stat)); req->cmd =P9_CMD_STAT ;send_9p (dev, req,"U" , fid); rcv_9p(dev, req, "uuuUQUUULSSSSSUUU", &total, &stat->size, &stat->type,
Signature · 1 line
2.35.3
Juergen Gross, le mar. 06 févr. 2024 07:17:21 +0100, a ecrit:
Quoted 4 lines
The early error exit in
p9_stat()returns without zeroing thep9_statbuffer, resulting infree()being called with an uninitialized pointer.Fix that by doing the zeroing first.
This is not coherent with the usual conventions: when a function fails, it is supposed not to have done anything, and thus the caller shouldn't have to clean anything.
I.e. i'd rather see the free_stat() call be put after the check for an error returned by p9_stat.
Quoted 26 lines
Reported-by Julien Grall <[email protected]>Fixes 2d1dfccd3aa3 ("Mini-OS: add read and write support to 9pfsfront")Signed-off-by Juergen Gross <[email protected]>--- 9pfront.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)9pfront.c +2
-1@@ -716,10 +716,11 @@ static int p9_stat(struct dev_9pfs *dev, uint32_t fid, struct p9_stat *stat)uint16_t total;int ret; +memset (stat,0 ,sizeof (*stat)); +if ( !req )return EAGAIN ; -memset (stat,0 ,sizeof (*stat)); req->cmd =P9_CMD_STAT ;send_9p (dev, req,"U" , fid); rcv_9p(dev, req, "uuuUQUUULSSSSSUUU", &total, &stat->size, &stat->type,Signature · 1 line
2.35.3
Quoted 4 lines · Samuel Thibault
Juergen Gross, le mar. 06 févr. 2024 07:17:21 +0100, a ecrit:
Quoted 3 lines
The early error exit in
p9_stat()returns without zeroing thep9_statbuffer, resulting infree()being called with an uninitialized pointer.
Quoted 8 lines
Quoted 1 line
Fix that by doing the zeroing first.
This is not coherent with the usual conventions: when a function fails, it is supposed not to have done anything, and thus the caller shouldn't have to clean anything.
I.e. i'd rather see the
free_stat()call be put after the check for an error returned byp9_stat.
I can do that, but this would require two calls of free_stat() (one in p9_stat() in an error case reported via req->result, and one in the caller of p9_stat() in case of no error).
Juergen
Jürgen Groß, le mar. 06 févr. 2024 16:37:17 +0100, a ecrit:
Quoted 11 lines · Samuel Thibault
Quoted 10 lines
Juergen Gross, le mar. 06 févr. 2024 07:17:21 +0100, a ecrit:
Quoted 4 lines
The early error exit in
p9_stat()returns without zeroing thep9_statbuffer, resulting infree()being called with an uninitialized pointer.Fix that by doing the zeroing first.
This is not coherent with the usual conventions: when a function fails, it is supposed not to have done anything, and thus the caller shouldn't have to clean anything.
Quoted 6 lines
Quoted 2 lines
I.e. i'd rather see the
free_stat()call be put after the check for an error returned byp9_stat.I can do that, but this would require two calls of
free_stat()(one inp9_stat()in an error case reported viareq->result, and one in the caller ofp9_stat()in case of no error).
Indeed, but that still looks more coherent with usual conventions.
Samuel