public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc: Avoid writing '\0' out of string's border
@ 2014-08-27 22:43 Chen Gang
  2014-08-27 22:51 ` Konstantin Serebryany
  2014-09-01  8:42 ` Jakub Jelinek
  0 siblings, 2 replies; 6+ messages in thread
From: Chen Gang @ 2014-08-27 22:43 UTC (permalink / raw)
  To: jakub, dodji, kcc, dvyukov; +Cc: gcc-patches List, Jeff Law

'max_len' is the maximized length of 'name', so for writing '\0' to
"name[max_len]", it is out of string's border, need use "max_len - 1"
instead of.

Pass normal test suite: "configure && make && make check && compare",
I guess, at present, it is not really used by outside, though.

2014-08-27  Chen Gang  <gang.chen.5i5j@gmail.com>

	* sanitizer_common/sanitizer_linux_libcdep.cc
	(SanitizerGetThreadName): Avoid writing '\0' out of string's
	border
---
 libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
index e754b26..b9089d5 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -140,7 +140,7 @@ bool SanitizerGetThreadName(char *name, int max_len) {
   if (prctl(PR_GET_NAME, (unsigned long)buff, 0, 0, 0))  // NOLINT
     return false;
   internal_strncpy(name, buff, max_len);
-  name[max_len] = 0;
+  name[max_len - 1] = 0;
   return true;
 #else
   return false;
-- 
1.9.3

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

end of thread, other threads:[~2014-09-01  8:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27 22:43 [PATCH] libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc: Avoid writing '\0' out of string's border Chen Gang
2014-08-27 22:51 ` Konstantin Serebryany
2014-08-27 22:58   ` Chen Gang
2014-08-30  3:53     ` Chen Gang
2014-09-01  8:42 ` Jakub Jelinek
2014-09-01  8:52   ` Chen Gang

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 read-only IMAP folder(s) and NNTP newsgroup(s).