From owner-svn-src-all@freebsd.org Wed Dec 16 13:56:20 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 22056A49AF2; Wed, 16 Dec 2015 13:56:20 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E4A771747; Wed, 16 Dec 2015 13:56:19 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBG9H7aA049475; Wed, 16 Dec 2015 09:17:07 GMT (envelope-from des@FreeBSD.org) Received: (from des@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBG9H7E1049474; Wed, 16 Dec 2015 09:17:07 GMT (envelope-from des@FreeBSD.org) Message-Id: <201512160917.tBG9H7E1049474@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: des set sender to des@FreeBSD.org using -f From: =?UTF-8?Q?Dag-Erling_Sm=c3=b8rgrav?= Date: Wed, 16 Dec 2015 09:17:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292330 - head/lib/libfetch X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Dec 2015 13:56:20 -0000 Author: des Date: Wed Dec 16 09:17:07 2015 New Revision: 292330 URL: https://svnweb.freebsd.org/changeset/base/292330 Log: Reset bufpos to 0 immediately after refilling the buffer. Otherwise, we risk leaving the connection in an indeterminate state if the server fails to send a chunk delimiter. Depending on the application and on the sizes of the preceding chunks, the result can be anything from missing data to a segfault. With this patch, it will be reported as a protocol error. PR: 204771 MFC after: 1 week Modified: head/lib/libfetch/http.c Modified: head/lib/libfetch/http.c ============================================================================== --- head/lib/libfetch/http.c Wed Dec 16 09:16:06 2015 (r292329) +++ head/lib/libfetch/http.c Wed Dec 16 09:17:07 2015 (r292330) @@ -246,8 +246,9 @@ http_fillbuf(struct httpio *io, size_t l io->error = errno; return (-1); } + io->bufpos = 0; io->buflen = nbytes; - io->chunksize -= io->buflen; + io->chunksize -= nbytes; if (io->chunksize == 0) { if (fetch_read(io->conn, &ch, 1) != 1 || ch != '\r' || @@ -255,8 +256,6 @@ http_fillbuf(struct httpio *io, size_t l return (-1); } - io->bufpos = 0; - return (io->buflen); }