From: "Chun Yan Liu" Subject: Re: [PATCH V5 2/7] libxl_read_file_contents: add new entry to read sysfs file Date: Thu, 25 Jun 2015 23:48:18 -0600 Message-ID: <558D7442020000660004C2F1@relay2.provo.novell.com> References: <1435226838-3067-1-git-send-email-cyliu@suse.com> <1435226838-3067-3-git-send-email-cyliu@suse.com> <21899.57676.368102.982820@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21899.57676.368102.982820@mariner.uk.xensource.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Juergen Gross , wei.liu2@citrix.com, ian.campbell@citrix.com, george.dunlap@eu.citrix.com, xen-devel@lists.xen.org, Jim Fehlig List-Id: xen-devel@lists.xenproject.org >>> On 6/25/2015 at 07:09 PM, in message <21899.57676.368102.982820@mariner.uk.xensource.com>, Ian Jackson wrote: > Chunyan Liu writes ("[PATCH V5 2/7] libxl_read_file_contents: add new entry > to read sysfs file"): > > Sysfs file has size=4096 but actual file content is less than that. > > Current libxl_read_file_contents will treat it as error when file size > > and actual file content differs, so reading sysfs file content with > > this function always fails. > > > > Add a new entry libxl_read_sysfs_file_contents to handle sysfs file > > specially. It would be used in later pvusb work. > > I think this still fails to detect a situation where the file is > unexpectedly longer than the requested size ? + } else if (feof(f)) { + if (rs < datalen && tolerate_shrinking_file) { + datalen = rs; + } else { If the file is bigger than the requested size, it will fall to this branch and report error. Do you mean I should report another error message separately? - Chunyan + LOG(ERROR, "%s changed size while we were reading it", + filename); + goto xe; + } + } else { > > As we wrote earlier: > > > > > Is there any risk that the file is actually bigger than advertised, > > > > rather than smaller ? > > > > > > For sysfs file, couldn't be bigger. > > > > Then you should detect the condition that the file is bigger, and call > > it an error. > > Thanks, > Ian. > >