[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink



On Mon, Dec 14, 2009 at 12:07:18PM +0100, Jim Meyering wrote:
> Without this patch, a symlink pointing to a 4096-byte name
> could make this code write NUL into the byte beyond end of buffer:
> 
>     if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) < 0) {
>         virReportSystemError(conn, errno,
>                              _("cannot resolve driver link %s"), driver_link);
>         goto cleanup;
>     }
>     devpath[n] = '\0';
> 
> 
> >From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering redhat com>
> Date: Mon, 14 Dec 2009 12:05:38 +0100
> Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
> 
> * src/node_device/node_device_driver.c (update_driver_name): Leave
> one byte for the trailing NUL we'll append.
> ---
>  src/node_device/node_device_driver.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
> index f083f16..eda5d5e 100644
> --- a/src/node_device/node_device_driver.c
> +++ b/src/node_device/node_device_driver.c
> @@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn,
>          goto cleanup;
>      }
> 
> -    if ((n = readlink(driver_link, devpath, sizeof devpath)) < 0) {
> +    if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) < 0) {
>          virReportSystemError(conn, errno,
>                               _("cannot resolve driver link %s"), driver_link);
>          goto cleanup;

  Actually, now that I think about it, shouldn't we use
virFileResolveLink() there and drop the static buffer and use the
convenience wrapper function ? That would be even cleaner/safer no ?

  I checked that virFileResolveLink() does not suffer from this
and might not have the static 4K limitation.

   thoughs ?

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]