[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-fsdevel
Subject:    vfs: Don\'t update buflen when prepend() fails.
From:       Tetsuo Handa <penguin-kernel () i-love ! sakura ! ne ! jp>
Date:       2008-07-31 1:20:49
Message-ID: 200807310120.m6V1Knro083783 () www262 ! sakura ! ne ! jp
[Download RAW message or body]

I think *buflen should not be updated when prepend() fails.
Also, comparison should be (signed int) < (signed int) rather than
(signed int) < 0, in case of *buflen becomes positive after subtracting namelen.
Calling again after failure (or calling once with nagative namelen value) can
make *buflen positive and trigger buffer overrun).

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 fs/dcache.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- linux-2.6.27-rc1.orig/fs/dcache.c
+++ linux-2.6.27-rc1/fs/dcache.c
@@ -1775,9 +1775,9 @@ shouldnt_be_hashed:
 
 static int prepend(char **buffer, int *buflen, const char *str, int namelen)
 {
-	*buflen -= namelen;
-	if (*buflen < 0)
+	if (*buflen < namelen)
 		return -ENAMETOOLONG;
+	*buflen -= namelen;
 	*buffer -= namelen;
 	memcpy(*buffer, str, namelen);
 	return 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic