From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWP3W-0007mS-ME for qemu-devel@nongnu.org; Fri, 13 Mar 2015 08:51:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWP3V-0000wq-Tw for qemu-devel@nongnu.org; Fri, 13 Mar 2015 08:51:10 -0400 Message-ID: <5502DD26.6070401@redhat.com> Date: Fri, 13 Mar 2015 13:50:46 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1426244956-5316-1-git-send-email-zhaoshenglong@huawei.com> In-Reply-To: <1426244956-5316-1-git-send-email-zhaoshenglong@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] hw/9pfs/virtio-9p-proxy: Fix possible overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Shannon Zhao , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, hangaohuai@huawei.com, qemu-trivial@nongnu.org, mjt@tls.msk.ru, peter.huangpeng@huawei.com, aneesh.kumar@linux.vnet.ibm.com, shannon.zhao@linaro.org On 13/03/2015 12:09, Shannon Zhao wrote: > + g_assert(strlen(path) < sizeof(helper.sun_path)); Ok. > sockfd = socket(AF_UNIX, SOCK_STREAM, 0); > if (sockfd < 0) { > fprintf(stderr, "failed to create socket: %s\n", strerror(errno)); > return -1; > } > - strcpy(helper.sun_path, path); > + strncpy(helper.sun_path, path, sizeof(helper.sun_path)); strcpy is okay here. strncpy makes people think of what happens if strlen(path) == sizeof(helper.sun_path). While this cannot happen here because of the assertion, the function should still be used with care. Paolo