From patchwork Tue Nov 23 12:59:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 72649 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D9FF5B70E2 for ; Wed, 24 Nov 2010 00:00:08 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754016Ab0KWNAC (ORCPT ); Tue, 23 Nov 2010 08:00:02 -0500 Received: from wine.ocn.ne.jp ([122.1.235.145]:63169 "EHLO smtp.wine.ocn.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005Ab0KWNAA (ORCPT ); Tue, 23 Nov 2010 08:00:00 -0500 Received: from CLAMP (p7114-ipbf1101marunouchi.tokyo.ocn.ne.jp [124.101.228.114]) by smtp.wine.ocn.ne.jp (Postfix) with ESMTP id 366923CF8; Tue, 23 Nov 2010 21:59:59 +0900 (JST) To: mtk.manpages@gmail.com Cc: linux-man@vger.kernel.org, netdev@vger.kernel.org Subject: Patch for man unix(7) From: Tetsuo Handa References: <201010171428.DDC17187.FFFJSLtOOHOMQV@I-love.SAKURA.ne.jp> <201010262115.FEH09326.OMFJHSVOFLQFOt@I-love.SAKURA.ne.jp> In-Reply-To: <201010262115.FEH09326.OMFJHSVOFLQFOt@I-love.SAKURA.ne.jp> Message-Id: <201011232159.DFE78143.tSHMFQOLFVFJOO@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Tue, 23 Nov 2010 21:59:51 +0900 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From f388eedbdc0b099bb9f36ab007f9370432abb300 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Tue, 23 Nov 2010 21:34:25 +0900 Subject: [PATCH] unix.7: Fix description of "pathname" sockets Since unix_mkname() in net/unix/af_unix.c does ((char *)sunaddr)[len] = 0; rather than ((char *)sunaddr)[len - 1] = 0; , sunaddr->sun_path may not be terminated with a null byte if len == sizeof(*sunaddr). Therefore, the caller of getsockname(), getpeername(), accept() must not assume that sunaddr->sun_path contains a null-terminated pathname even if the returned addrlen is greater than sizeof(sa_family_t) and sun_path[0] != '\0'. Signed-off-by: Tetsuo Handa --- man7/unix.7 | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) diff --git a/man7/unix.7 b/man7/unix.7 index b53328b..7b0b47c 100644 --- a/man7/unix.7 +++ b/man7/unix.7 @@ -80,10 +80,23 @@ When the address of the socket is returned by and .BR accept (2), its length is -.IR "offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1" , +.IR "offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1". +Note that this length can be one byte larger than +.IR "sizeof(struct sockaddr_un)" +because +.BR bind (2) +accepts +.IR sun_path +which is not terminated with a null byte ('\\0'). +Therefore, you must not use string manipulation functions (e.g. strlen(), +printf("%s")) against +.IR sun_path +because +.BR getsockname (2), +.BR getpeername (2), and -.I sun_path -contains the null-terminated pathname. +.BR accept (2) +may not have stored a null-terminated string. .IP * .IR unnamed : A stream socket that has not been bound to a pathname using