Received: from eggs.gnu.org ([2001:4830:134:3::10]:56738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlyIX-0007hQ-6x for qemu-devel@nongnu.org; Mon, 10 Jun 2013 05:21:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UlyIS-0000Ij-JI for qemu-devel@nongnu.org; Mon, 10 Jun 2013 05:21:57 -0400 Received: from mail-ea0-x236.google.com ([2a00:1450:4013:c01::236]:56396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlyIS-0000Id-Co for qemu-devel@nongnu.org; Mon, 10 Jun 2013 05:21:52 -0400 Received: by mail-ea0-f182.google.com with SMTP id d10so1379195eaj.27 for ; Mon, 10 Jun 2013 02:21:51 -0700 (PDT) Date: Mon, 10 Jun 2013 11:21:49 +0200 From: Stefan Hajnoczi Message-ID: <20130610092149.GB5745@stefanha-thinkpad.redhat.com> References: <1370745294-19933-1-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1370745294-19933-1-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH] curl: refuse to open URL from HTTP server without range support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , qemu-devel@nongnu.org, stefanha@redhat.com, rjones@redhat.com On Sun, Jun 09, 2013 at 10:34:54AM +0800, Fam Zheng wrote: > @@ -110,14 +111,14 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, > return 0; > } > > -static size_t curl_size_cb(void *ptr, size_t size, size_t nmemb, void *opaque) > +static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque) > { > - CURLState *s = ((CURLState*)opaque); > + BDRVCURLState *s = opaque; > size_t realsize = size * nmemb; > - size_t fsize; > + const char *accept_line = "Accept-Ranges: bytes"; > > - if(sscanf(ptr, "Content-Length: %zd", &fsize) == 1) { > - s->s->len = fsize; > + if (strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) { > + s->accept_range = true; > } This still assumes ptr is NUL-terminated. You need to pass size * nmemb instead of strlen(accept_line).