aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorDaniel Colascione2014-03-21 20:04:24 -0700
committerDaniel Colascione2014-03-21 20:04:24 -0700
commitea64063f079e31f824de1f471074c69281fb06fd (patch)
tree16f9e845a7345ce66c03c73408d323de5e7ea24f /src/process.c
parentaa4659075414a2730535eeb419847d761eb76f0d (diff)
downloademacs-ea64063f079e31f824de1f471074c69281fb06fd.tar.gz
emacs-ea64063f079e31f824de1f471074c69281fb06fd.zip
Do not read unitialized memory in conv_sockaddr_to_lisp
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/process.c b/src/process.c
index 187627dd85a..10a2984a053 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2010,10 +2010,22 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
2010 case AF_LOCAL: 2010 case AF_LOCAL:
2011 { 2011 {
2012 struct sockaddr_un *sockun = (struct sockaddr_un *) sa; 2012 struct sockaddr_un *sockun = (struct sockaddr_un *) sa;
2013 for (i = 0; i < sizeof (sockun->sun_path); i++) 2013 ptrdiff_t name_length = len - offsetof (struct sockaddr_un, sun_path);
2014 if (sockun->sun_path[i] == 0) 2014 /* If the first byte is NUL, the name is a Linux abstract
2015 break; 2015 socket name, and the name can contain embedded NULs. If
2016 return make_unibyte_string (sockun->sun_path, i); 2016 it's not, we have a NUL-terminated string. Be careful not
2017 to walk past the end of the object looking for the name
2018 terminator, however. */
2019 if (name_length > 0 && sockun->sun_path[0] != '\0')
2020 {
2021 const char* terminator =
2022 memchr (sockun->sun_path, '\0', name_length);
2023
2024 if (terminator)
2025 name_length = terminator - (const char*) sockun->sun_path;
2026 }
2027
2028 return make_unibyte_string (sockun->sun_path, name_length);
2017 } 2029 }
2018#endif 2030#endif
2019 default: 2031 default: