aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorDaniel Colascione2014-03-22 23:07:54 -0700
committerDaniel Colascione2014-03-22 23:07:54 -0700
commite4e40f72f3cfd29c98f6a450490cdb4caf1bdc68 (patch)
treee1f2b5a6f98f3f4dd2a4d7889b0495e4dd7b36c6 /src/process.c
parente611af505f8d411c5f11c012eaaafeb28cabe0c4 (diff)
downloademacs-e4e40f72f3cfd29c98f6a450490cdb4caf1bdc68.tar.gz
emacs-e4e40f72f3cfd29c98f6a450490cdb4caf1bdc68.zip
Backport memory fix (2014-03-22T03:04:53Z!dancol@dancol.org) from trunk
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 6f89408b5ee..fd34eb08d9d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2013,10 +2013,22 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
2013 case AF_LOCAL: 2013 case AF_LOCAL:
2014 { 2014 {
2015 struct sockaddr_un *sockun = (struct sockaddr_un *) sa; 2015 struct sockaddr_un *sockun = (struct sockaddr_un *) sa;
2016 for (i = 0; i < sizeof (sockun->sun_path); i++) 2016 ptrdiff_t name_length = len - offsetof (struct sockaddr_un, sun_path);
2017 if (sockun->sun_path[i] == 0) 2017 /* If the first byte is NUL, the name is a Linux abstract
2018 break; 2018 socket name, and the name can contain embedded NULs. If
2019 return make_unibyte_string (sockun->sun_path, i); 2019 it's not, we have a NUL-terminated string. Be careful not
2020 to walk past the end of the object looking for the name
2021 terminator, however. */
2022 if (name_length > 0 && sockun->sun_path[0] != '\0')
2023 {
2024 const char* terminator =
2025 memchr (sockun->sun_path, '\0', name_length);
2026
2027 if (terminator)
2028 name_length = terminator - (const char*) sockun->sun_path;
2029 }
2030
2031 return make_unibyte_string (sockun->sun_path, name_length);
2020 } 2032 }
2021#endif 2033#endif
2022 default: 2034 default: