lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <SL2PR06MB3082F89D5AE9436928A934F6BDB79@SL2PR06MB3082.apcprd06.prod.outlook.com>
Date:   Wed, 13 Oct 2021 07:20:25 +0000
From:   王擎 <wangqing@...o.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC:     "linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: 回复: 回复: [PATCH] usb: replace snprintf in show functions with sysfs_emit

 
>> >> On Tue, Oct 12, 2021 at 08:27:47PM -0700, Qing Wang wrote:
>> >> coccicheck complains about the use of snprintf() in sysfs show functions.
>> >> 
>> >> Fix the following coccicheck warning:
>> >> drivers/usb/core/sysfs.c:730:8-16: WARNING: use scnprintf or sprintf.
>> >> drivers/usb/core/sysfs.c:921:8-16: WARNING: use scnprintf or sprintf.
>> >> 
>> >> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>> >> 
>> >> Signed-off-by: Qing Wang <wangqing@...o.com>
>> >> ---
>> >>  drivers/usb/core/sysfs.c | 4 ++--
>> >>  1 file changed, 2 insertions(+), 2 deletions(-)
>> >> 
>> >> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
>> >> index fa2e49d..6387c0d 100644
>> >> --- a/drivers/usb/core/sysfs.c
>> >> +++ b/drivers/usb/core/sysfs.c
>> >> @@ -727,7 +727,7 @@ static ssize_t authorized_show(struct device *dev,
>> >>                               struct device_attribute *attr, char *buf)
>> >>  {
>> >>        struct usb_device *usb_dev = to_usb_device(dev);
>> >> -     return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
>> >> +     return sysfs_emit(buf, "%u\n", usb_dev->authorized);
>> >>  }
>> >>  
>> >>  /*
>> >> @@ -918,7 +918,7 @@ static ssize_t authorized_default_show(struct device *dev,
>> >>        struct usb_hcd *hcd;
>> >>  
>> >>        hcd = bus_to_hcd(usb_bus);
>> >> -     return snprintf(buf, PAGE_SIZE, "%u\n", hcd->dev_policy);
>> >> +     return sysfs_emit(buf, "%u\n", hcd->dev_policy);
>> >>  }
>> >>  
>> >>  static ssize_t authorized_default_store(struct device *dev,
>> >> -- 
>> >> 2.7.4
>> >> 
>> > 
>> > If you are going to change this file, you should do this for all of the
>> > sysfs show functions in this file, not just 2 of them, right?  Please
>> > change this patch to do that.
>> >
>> > thanks,
>> > 
>> > greg k-h
>> 
>> Only these 2 snprintf need to be modified, other show functions
>> used sprintf do not need to modify.
> 
> I do not think you understand the change you are trying to make here.
> 
> Either the whole file should use the same api, or just leave it as-is as
> it obviously works properly today :)
> 
> thanks,
> 
> greg k-h

snprintf() returns the length of the string, not the length actually written.
Here only correct this issue, as to whether it overflows should be 
guaranteed by the caller of sprintf().

Thanks,

Qing

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ