diff options
| author | Daniel Colascione | 2014-03-21 20:04:24 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2014-03-21 20:04:24 -0700 |
| commit | ea64063f079e31f824de1f471074c69281fb06fd (patch) | |
| tree | 16f9e845a7345ce66c03c73408d323de5e7ea24f /src | |
| parent | aa4659075414a2730535eeb419847d761eb76f0d (diff) | |
| download | emacs-ea64063f079e31f824de1f471074c69281fb06fd.tar.gz emacs-ea64063f079e31f824de1f471074c69281fb06fd.zip | |
Do not read unitialized memory in conv_sockaddr_to_lisp
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/process.c | 20 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c491119041f..504716f8915 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-03-22 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * process.c (conv_sockaddr_to_lisp): When extracting the string | ||
| 4 | names of AF_LOCAL sockets, stop before reading uninitialized | ||
| 5 | memory. | ||
| 6 | |||
| 1 | 2014-03-21 Daniel Colascione <dancol@dancol.org> | 7 | 2014-03-21 Daniel Colascione <dancol@dancol.org> |
| 2 | 8 | ||
| 3 | * xterm.c (x_bitmap_icon): Stop reading the icon bitmap from disk | 9 | * xterm.c (x_bitmap_icon): Stop reading the icon bitmap from disk |
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: |