lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <51E78B21.50907@asianux.com>
Date:	Thu, 18 Jul 2013 14:28:49 +0800
From:	Chen Gang <gang.chen@...anux.com>
To:	linux@...izon.com, Jiri Kosina <jkosina@...e.cz>,
	andriy.shevchenko@...ux.intel.com, andrei.emeltchenko@...el.com
CC:	Andrew Morton <akpm@...ux-foundation.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] lib/vsprintf.c: fix the incorrect return value of vsnprintf()

When "str >= end", necessary to reset 'str' to "end - 1", or the return
value will be larger than the real one, the callers which depend on the
return value, may cause memory overflow.

When for copying constant string, 'str' is point to destination buffer,
so it need add 'copy' (for destination buffer), not 'read' (for source
buffer).

Also add white space between variable and operator to make code cleaner.

Signed-off-by: Chen Gang <gang.chen@...anux.com>
---
 lib/vsprintf.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 739a363..b153768 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1542,7 +1542,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 					copy = end - str;
 				memcpy(str, old_fmt, copy);
 			}
-			str += read;
+			str += copy;
 			break;
 		}
 
@@ -1662,12 +1662,14 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 	if (size > 0) {
 		if (str < end)
 			*str = '\0';
-		else
+		else {
 			end[-1] = '\0';
+			str = end - 1;
+		}
 	}
 
 	/* the trailing null byte doesn't count towards the total */
-	return str-buf;
+	return str - buf;
 
 }
 EXPORT_SYMBOL(vsnprintf);
-- 
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ