git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mingw: consider that UNICODE_STRING::Length counts bytes
@ 2016-12-19 21:32 Max Kirillov
  2016-12-19 21:57 ` Junio C Hamano
  2016-12-20 15:16 ` Johannes Schindelin
  0 siblings, 2 replies; 6+ messages in thread
From: Max Kirillov @ 2016-12-19 21:32 UTC (permalink / raw)
  To: Junio C Hamano, Johannes Schindelin, Karsten Blees; +Cc: Max Kirillov, git

UNICODE_STRING::Length field means size of buffer in bytes[1], despite of buffer
itself being array of wchar_t. Because of that terminating zero is placed twice
as far. Fix it.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa380518.aspx

Signed-off-by: Max Kirillov <max@max630.net>
---
Access outside of buffer was very unlikely (for that user needed to redirect
standard fd to a file with path longer than ~250 symbols), it still did not
seem to do any harm, and otherwise it did not break because only substring is
checked, but it was still incorrect.
 compat/winansi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/winansi.c b/compat/winansi.c
index 3be60ce..6b4f736 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -553,7 +553,7 @@ static void detect_msys_tty(int fd)
 			buffer, sizeof(buffer) - 2, &result)))
 		return;
 	name = nameinfo->Name.Buffer;
-	name[nameinfo->Name.Length] = 0;
+	name[nameinfo->Name.Length / sizeof(*name)] = 0;
 
 	/* check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX') */
 	if (!wcsstr(name, L"msys-") || !wcsstr(name, L"-pty"))
-- 
2.3.4.2801.g3d0809b


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] mingw: consider that UNICODE_STRING::Length counts bytes
@ 2016-12-17 13:20 Max Kirillov
  0 siblings, 0 replies; 6+ messages in thread
From: Max Kirillov @ 2016-12-17 13:20 UTC (permalink / raw)
  To: Junio C Hamano, Johannes Schindelin, Karsten Blees; +Cc: Max Kirillov, git

UNICODE_STRING::Length field means size of buffer in bytes[1], despite of buffer
itself being array of wchar_t. Because of that terminating zero is placed twice
as far. Fix it.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa380518.aspx

Signed-off-by: Max Kirillov <max@max630.net>
---
Access outside of buffer was very unlikely (for that user needed to redirect
standard fd to a file with path longer than ~250 symbols), it still did not
seem to do any harm, and otherwise it did not break because only substring is
checked, but it was still incorrect.
 compat/winansi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/winansi.c b/compat/winansi.c
index 3be60ce..6b4f736 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -553,7 +553,7 @@ static void detect_msys_tty(int fd)
 			buffer, sizeof(buffer) - 2, &result)))
 		return;
 	name = nameinfo->Name.Buffer;
-	name[nameinfo->Name.Length] = 0;
+	name[nameinfo->Name.Length / sizeof(*name)] = 0;
 
 	/* check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX') */
 	if (!wcsstr(name, L"msys-") || !wcsstr(name, L"-pty"))
-- 
2.3.4.2801.g3d0809b


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-20 17:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-19 21:32 [PATCH] mingw: consider that UNICODE_STRING::Length counts bytes Max Kirillov
2016-12-19 21:57 ` Junio C Hamano
2016-12-20  5:21   ` Max Kirillov
2016-12-20 15:16 ` Johannes Schindelin
2016-12-20 17:07   ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2016-12-17 13:20 Max Kirillov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).