]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
test_firmware: Use correct snprintf() limit
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 15 May 2019 09:33:22 +0000 (12:33 +0300)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1838700
commit bd17cc5a20ae9aaa3ed775f360b75ff93cd66a1d upstream.

The limit here is supposed to be how much of the page is left, but it's
just using PAGE_SIZE as the limit.

The other thing to remember is that snprintf() returns the number of
bytes which would have been copied if we had had enough room.  So that
means that if we run out of space then this code would end up passing a
negative value as the limit and the kernel would print an error message.
I have change the code to use scnprintf() which returns the number of
bytes that were successfully printed (not counting the NUL terminator).

Fixes: c92316bf8e94 ("test_firmware: add batched firmware tests")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
lib/test_firmware.c

index 1aa58906863ba33c109abd4ae8cc73b823c357cb..b91b0f165498676db1e5fa8f9718a075219a10de 100644 (file)
@@ -222,30 +222,30 @@ static ssize_t config_show(struct device *dev,
 
        mutex_lock(&test_fw_mutex);
 
-       len += snprintf(buf, PAGE_SIZE,
+       len += scnprintf(buf, PAGE_SIZE - len,
                        "Custom trigger configuration for: %s\n",
                        dev_name(dev));
 
        if (test_fw_config->name)
-               len += snprintf(buf+len, PAGE_SIZE,
+               len += scnprintf(buf+len, PAGE_SIZE - len,
                                "name:\t%s\n",
                                test_fw_config->name);
        else
-               len += snprintf(buf+len, PAGE_SIZE,
+               len += scnprintf(buf+len, PAGE_SIZE - len,
                                "name:\tEMTPY\n");
 
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "num_requests:\t%u\n", test_fw_config->num_requests);
 
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "send_uevent:\t\t%s\n",
                        test_fw_config->send_uevent ?
                        "FW_ACTION_HOTPLUG" :
                        "FW_ACTION_NOHOTPLUG");
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "sync_direct:\t\t%s\n",
                        test_fw_config->sync_direct ? "true" : "false");
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx);
 
        mutex_unlock(&test_fw_mutex);