- g = string_cat(g, US" domain AF_UNIX");
- g = string_fmt_append(g, " lcl %s%s",
- sa_unp->sun_path[0] ? US"" : US"@",
- sa_unp->sun_path[0] ? sa_unp->sun_path : sa_unp->sun_path+1);
- if (getpeername(fd, &a, &alen) == 0)
- g = string_fmt_append(g, " rmt %s%s",
- sa_unp->sun_path[0] ? US"" : US"@",
- sa_unp->sun_path[0] ? sa_unp->sun_path : sa_unp->sun_path+1);
- break;
+ g = string_cat(g, US"domain AF_UNIX");
+ if (alen > sizeof(sa_family_t)) /* not unix(7) "unnamed socket" */
+ g = string_fmt_append(g, " lcl %s%s",
+ sunp->sun_path[0] ? US"" : US"@",
+ sunp->sun_path[0] ? sunp->sun_path : sunp->sun_path+1);
+ alen = sizeof(*sunp);
+ if (getpeername(fd, sunp, &alen) == 0)
+ g = string_fmt_append(g, " rmt %s%s",
+ sunp->sun_path[0] ? US"" : US"@",
+ sunp->sun_path[0] ? sunp->sun_path : sunp->sun_path+1);
+ break;