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

Re: [libvirt] [PATCH] portability to non-glibc: don't use realpath(..., NULL)



On Tue, Jan 26, 2010 at 05:48:59PM +0100, Jim Meyering wrote:
> Using realpath like that is not portable, and providing
> a buffer instead of NULL is wasteful and harder to code properly.
> Instead, use gnulib's canonicalize_file_name, which does
> the same job portably:
> 
> >From 4afea6b59e2be6c28b45ef59a6a2f896eed44dba Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering redhat com>
> Date: Tue, 26 Jan 2010 17:13:45 +0100
> Subject: [PATCH] portability to non-glibc: don't use realpath(..., NULL)
> 
> it causes a NULL-dereference on some systems like Solaris 10.
> * src/node_device/node_device_linux_sysfs.c. Include <stdlib.h>.
> (get_sriov_function): Use canonicalize_filen_name, not realpath.
> * bootstrap (modules): Add canonicalize-lgpl.
> ---
>  bootstrap                                 |    1 +
>  src/node_device/node_device_linux_sysfs.c |    6 ++++--
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/bootstrap b/bootstrap
> index aec5d05..cc3c6ef 100755
> --- a/bootstrap
> +++ b/bootstrap
> @@ -68,6 +68,7 @@ modules='
>  areadlink
>  base64
>  c-ctype
> +canonicalize-lgpl
>  close
>  connect
>  getaddrinfo
> diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
> index 33e658d..c1fce5d 100644
> --- a/src/node_device/node_device_linux_sysfs.c
> +++ b/src/node_device/node_device_linux_sysfs.c
> @@ -24,6 +24,7 @@
> 
>  #include <fcntl.h>
>  #include <sys/stat.h>
> +#include <stdlib.h>
> 
>  #include "node_device_driver.h"
>  #include "node_device_hal.h"
> @@ -242,7 +243,8 @@ out:
>  static int get_sriov_function(const char *device_link,
>                                struct pci_config_address **bdf)
>  {
> -    char *device_path = NULL, *config_address = NULL;
> +    char *config_address = NULL;
> +    char *device_path = NULL;
>      char errbuf[64];
>      int ret = SRIOV_ERROR;
> 
> @@ -259,7 +261,7 @@ static int get_sriov_function(const char *device_link,
> 
>      }
> 
> -    device_path = realpath(device_link, device_path);
> +    device_path = canonicalize_file_name (device_link);
>      if (device_path == NULL) {
>          memset(errbuf, '\0', sizeof(errbuf));
>          VIR_ERROR("Failed to resolve device link '%s': '%s'", device_link,

ACK

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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