From: Diego Nieto Cid <[email protected]>
../../nfs/ops.c: In function 'fetch_directory':
../../nfs/ops.c:1962:35: warning: pointer 'buf' may be used after 'realloc'
[-Wuse-after-free]
1962 | bp = newbuf + (bp - buf);
| ~~~~^~~~~~
../../nfs/ops.c:1959:24: note: call to 'realloc' here
1959 | newbuf = realloc (buf, bufmalloced *= 2);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
nfs/ops.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/nfs/ops.c b/nfs/ops.c
index 55ff111d..95e8b11c 100644
--- a/nfs/ops.c
+++ b/nfs/ops.c
@@ -1955,11 +1955,12 @@ fetch_directory (struct iouser *cred, struct node *dir,
if (bp + reclen > buf + bufmalloced)
{
char *newbuf;
+ size_t current_size = bp - buf;
newbuf = realloc (buf, bufmalloced *= 2);
assert_backtrace (newbuf);
if (newbuf != buf)
- bp = newbuf + (bp - buf);
+ bp = newbuf + current_size;
buf = newbuf;
}
--
2.51.0