From bbc41cdbeb17497e002a4c8b712ca50dfeaaef31 Mon Sep 17 00:00:00 2001 From: iedowse Date: Sat, 12 May 2001 20:05:26 +0000 Subject: Extract the path from an AF_LOCAL sockaddr_un in a way that correctly terminates the string in all cases, based on code from netstat(1). The path in a sockaddr_un is terminated either by a '\0', or by the end of the sockaddr as defined by sun_len. Previously, the code could write the "safety" '\0' beyond the end of the sockaddr (sockaddr_un's need only be large enough to store sun_len bytes), and writing into the the supplied sockaddr is bad anyway. --- lib/libc/rpc/rpc_generic.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/libc/rpc/rpc_generic.c') diff --git a/lib/libc/rpc/rpc_generic.c b/lib/libc/rpc/rpc_generic.c index 81f0b6d..ad581a5 100644 --- a/lib/libc/rpc/rpc_generic.c +++ b/lib/libc/rpc/rpc_generic.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -621,8 +622,10 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf) #endif case AF_LOCAL: sun = nbuf->buf; - sun->sun_path[sizeof(sun->sun_path) - 1] = '\0'; /* safety */ - ret = strdup(sun->sun_path); + if (asprintf(&ret, "%.*s", (int)(sun->sun_len - + offsetof(struct sockaddr_un, sun_path)), + sun->sun_path) < 0) + return (NULL); break; default: return NULL; -- cgit v1.1