xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Zhongze Liu <blackskygg@gmail.com>
To: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: xen-devel@lists.xenproject.org, Wei Liu <wei.liu2@citrix.com>,
	David Scott <dave@recoil.org>
Subject: Re: [PATCH] tools: fix several "format-truncation" errors with GCC 7
Date: Tue, 13 Jun 2017 01:55:10 +0800	[thread overview]
Message-ID: <CAHrd_jrODib5XbfX8PbrbRDXHBgf8EXT+SZDNXRidF87hLweeg@mail.gmail.com> (raw)
In-Reply-To: <22846.35243.172129.757205@mariner.uk.xensource.com>

Hi Ian,

Thanks for pointing out the problems. I've consulted several
maintainers about this
and have drafted a new patch for it (in a new [patch v2] thread).
Please have a look
at it. Thanks.

Cheers,

Zhongze Liu.

2017-06-12 20:31 GMT+08:00 Ian Jackson <ian.jackson@eu.citrix.com>:
> Zhongze Liu writes ("[PATCH] tools: fix several "format-truncation" errors with GCC 7"):
>> replace several snprintf with asprintf in xenpmd and tools/ocmal/xc
>> to fix the "format-truncation" errors caused by incorrect size of buffers.
>
> Thanks for paying attention to the quality of our code, but:
>
> I wonder whether this cure is worse than the disease.  Using asprintf
> everywhere means additional error handling (which you have erroneously
> omitted) and additional potential for leaks etc. (for which I haven't
> analysed your patch).
>
> You say `"format-truncation" errors' but you mean compiler warnings
> from -Wformat-truncation, turned into errors by -Werror.  Is there
> any suggestion from a human that this code actually malfunctions ?
>
> Or does the compiler not just complain all the time about snprintf ?
>
>> -     char error_str[256];
> ...
>> -                     snprintf(error_str, sizeof(error_str),
>> -                              "%d: %s", errno, strerror(errno));
>
> This will not truncate unless the xc error string is too long, which
> is not.
>
>> -             snprintf(error_str, sizeof(error_str),
>> -                      "Unable to open XC interface");
>> +             asprintf(&error_str, "Unable to open XC interface");
>
> This is a fixed string of course.
>
>> -    char file_name[32];
> ...
>> @@ -110,12 +112,16 @@ FILE *get_next_battery_file(DIR *battery_dir,
>>          if ( strlen(dir_entries->d_name) < 4 )
>>              continue;
>>          if ( battery_info_type == BIF )
>> -            snprintf(file_name, 32, BATTERY_INFO_FILE_PATH,
>> -                     dir_entries->d_name);
>> +         rc = asprintf(&file_name, BATTERY_INFO_FILE_PATH,
>> +                       dir_entries->d_name);
>>          else
>> -            snprintf(file_name, 32, BATTERY_STATE_FILE_PATH,
>> -                     dir_entries->d_name);
>> -        file = fopen(file_name, "r");
>> +            rc = asprintf(&file_name, BATTERY_STATE_FILE_PATH,
>> +                       dir_entries->d_name);
>
> These filenames are all very formulaic.  I doubt they are being
> truncated even though the limit is only 32 bytes.
>
> Regards,
> Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

      reply	other threads:[~2017-06-12 17:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-12 12:07 [PATCH] tools: fix several "format-truncation" errors with GCC 7 Zhongze Liu
2017-06-12 12:31 ` Ian Jackson
2017-06-12 17:55   ` Zhongze Liu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHrd_jrODib5XbfX8PbrbRDXHBgf8EXT+SZDNXRidF87hLweeg@mail.gmail.com \
    --to=blackskygg@gmail.com \
    --cc=dave@recoil.org \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).