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

Re: [PATCH v2] xenpmd.c: use dynamic allocation


  • To: Manuel Bouyer <bouyer@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Thu, 28 Jan 2021 11:34:44 +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=5ApVa2gPEP02ELtrZLXf8BbgkeoFTgW1xAUpaGC0WTY=; b=gtNocsI3sVIqFzqfkleW6J4RfqOgcfXJkvHnUzKEcXNs2tDB2u2B3q4m1vDEkIimmlJwvgL9uosrkdSiffSOFleVJymaHGHegu8OKjuEu/3Rcm4M084pOIwDRIuXLzD8Ph8QDFKi2GguxOFO/uQUp2ed0NREgQvs7EnVtBkLJwAVMb5YFufF7+svgKtqG/2B/unkHrVLUWSWmdfDEltIIvORlGxxbDiS/dy+6MkVpJPKTxxwzyIZOHZyQ05hzKPtNcycSWvhpdlXIuGnwC4A+pEz8tQ8pt00F62vqTeV7BI84sgr7sz8KXh63OL53PRyys7Hc1sRtFZJzHn119yvoA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=loveNT0ggeCInRjgB8uH6uuElwdWTG9fkyd7xNA9Gz0MvmoCA3ORKf1hI8oUPKFS/66FAIDCoNQrWK8V6OkFnZKcRLEBSQ1R88kcHkXgoii8FcDQnqlEfVEWUrzBhY/WL8bu0IHtpzCsS8C2VZ8FE86fhUSZKtkOa+zs8m4+jieB0icJ6tffky4hUGZe/UrXXywBdUH8nNPDzAY/8V9xRh0H5cCOj1IjMaCvqZfO914wwMyqH9M7kzhRsXTA8SX6Y/+ZCjMFS9xw+cKX2zcE9CaDihEWRxbk+htZJ6DiGvPE9RjI9nhOqxPnCAh2eyisonJFkXPlM5i6k7AS9cVsgQ==
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 28 Jan 2021 10:35:00 +0000
  • Ironport-sdr: kjZ+DcNsdfPWQN4imUu3+1u9pkUOw3z3ORHVtmrIaPmyYufe1OsDM6Hn3VeLVQSsO79CfIdMnn ryPCI9GmlmarUP8AWin4HQ78jRHB0g38BUkXp+iAb+fNgsFFmriiVXbTFgahz0FTYf5USidbAo BDK7s+Wty4nqJR0zEF5qcjN+siox1J942gLnMt75hdxivgkttev+kv4YAfqtDwXM85ebTX3OxO rN+BWUa76Dk62TQtBb5iYQ/0WQsTaVjtkC+a76oVMq+l07ktd2Wjl9SYQNKklUWdOiwT38eYnY 9lw=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Jan 26, 2021 at 11:48:00PM +0100, Manuel Bouyer wrote:
> On NetBSD, d_name is larger than 256, so file_name[284] may not be large
> enough (and gcc emits a format-truncation error).
> Use asprintf() instead of snprintf() on a static on-stack buffer.
> 
> Signed-off-by: Manuel Bouyer <bouyer@xxxxxxxxxx>

Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

> ---
>  tools/xenpmd/xenpmd.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
> index 12b82cf43e..e432aad856 100644
> --- a/tools/xenpmd/xenpmd.c
> +++ b/tools/xenpmd/xenpmd.c
> @@ -101,7 +101,7 @@ FILE *get_next_battery_file(DIR *battery_dir,
>  {
>      FILE *file = 0;
>      struct dirent *dir_entries;
> -    char file_name[284];
> +    char *file_name;
>      int ret;
>      
>      do 
> @@ -112,16 +112,16 @@ FILE *get_next_battery_file(DIR *battery_dir,
>          if ( strlen(dir_entries->d_name) < 4 )
>              continue;
>          if ( battery_info_type == BIF ) 
> -            ret = snprintf(file_name, sizeof(file_name), 
> BATTERY_INFO_FILE_PATH,
> +            ret = asprintf(&file_name, BATTERY_INFO_FILE_PATH,
>                       dir_entries->d_name);
>          else 
> -            ret = snprintf(file_name, sizeof(file_name), 
> BATTERY_STATE_FILE_PATH,
> +            ret = asprintf(&file_name, BATTERY_STATE_FILE_PATH,
>                       dir_entries->d_name);
>          /* This should not happen but is needed to pass gcc checks */
>          if (ret < 0)
>              continue;
> -        file_name[sizeof(file_name) - 1] = '\0';
>          file = fopen(file_name, "r");
> +     free(file_name);

Hard tab. May I ask whether this can be fixed on commit so that
there's no need to resend a new version?

Thanks, Roger.



 


Rackspace

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