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

Re: [PATCH 20/24] If FILENAME_MAX is defined, use it instead of arbitrary value (fix format-truncation errors with GCC >= 7)


  • To: Manuel Bouyer <bouyer@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 29 Dec 2020 15:51:55 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zczBwuZiu0pOW8u1wPMKkqUHJLefuJuMntu7TSVTNho=; b=FgsO/ms39OaPbO4IoY13fvUq1+Ao2MlzlK3BhRhOPT12caCCB/FeK8eaewUT96HL1adwUBOgTxg1esukHV5aQLAmk4MX1jLE76OEB5c2IiCmrvd57E1fFeRXF6hN4U6PBJcRHXzB0N7zONWT/7ILSL6awhpkVixcU/ITBMqGmaw9dw5cxLmBx1lxgQN9A1jMgCx5IGN2S29yKRgE17Bdu/3VTtjYxK4O/lMMoByHwjFakEmIvSxXAvP6mo7lX0yFSU/CPnANxPgx2jRcrpkTRDXRDm+A4py/Amgp8wcUE7EzbNb8wyezA6YOMYCGfIDl3ua8/GCGGdy3rx6VvJBc6w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CYlKEAMiy5nc/HDhEeQF6G7IFSaDt3G6JbPMe+NjoSOuRkBd+aIol+MjEMB/rN8wPY3L9Boko2BpXhjNSw0Dp37q+SlVWOWyi9VHuydJoU03aFkrhgNQr77ftW6LLflM9zw5pEKMgxuWKjb0zz0Hk5Hr66BnV1bz1wPTuTktmW+eyDK+4KIGtdz/bCtEZiFyBmrMAaW6X65pI0cQH7T9AsOBs3UafpKCB8//nGo/Y7XRitYmt/I1IkvtfUgS4llZyptg++F5T14VUIeCsd90FX3+GN4f1n0s1UxRCm+5xZofSWOXzMrZxttbDs3yGQiQSqiyx6fO7Kh9B3Rd36UCNQ==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 29 Dec 2020 14:52:11 +0000
  • Ironport-sdr: Lc4hhdAmPuGEJZmxk1ka6/1vrU2i5pf7A9UINy3dFKFh2kjbMpz42+zgVzW7b/3eoQYP2qomI3 a+FqvPARf0XcpVXEKzTraFb4HEInx57ds/KtCxhUOj4VF5B88eDoLea3tQXsIZQBs4IODDeA4Z TIxQZ97SplDVInmukxDvXcnAJvZUgvi2rByfMM8zKbK/u5oMW6RRnNKymxHPm4zZRlvSAFBUMr ix2JG9wkLofLKWBbVqE108YpoqWEdtI5olaSfVPBcjxqWzZQjnB8LL0yhJUpH37arFkkxAArM3 Yds=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Mon, Dec 14, 2020 at 05:36:19PM +0100, Manuel Bouyer wrote:
> ---
>  tools/xenpmd/xenpmd.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
> index 12b82cf43e..cfd22e64e3 100644
> --- a/tools/xenpmd/xenpmd.c
> +++ b/tools/xenpmd/xenpmd.c
> @@ -101,7 +101,11 @@ FILE *get_next_battery_file(DIR *battery_dir,
>  {
>      FILE *file = 0;
>      struct dirent *dir_entries;
> +#ifdef FILENAME_MAX
> +    char file_name[FILENAME_MAX];
> +#else
>      char file_name[284];
> +#endif
>      int ret;

I think it's dangerous to do this, specially on the stack, GNU libc
manual states:

Usage Note: Don’t use FILENAME_MAX as the size of an array in which to
store a file name! You can’t possibly make an array that big! Use
dynamic allocation (see Memory Allocation) instead.

I think it would be better to replace the snprintf calls with asprintf
and free the buffer afterwards. Setting file_name to 284 should be
fine however, as d_name is 256 max and the paths above are 26 maximum
I think (27 with the nul character).

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.