From: Roel Kluin <12o3l@tiscali.nl>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@atrey.karlin.mff.cuni.cz
Subject: Re: [PATCH] Fix incorrect usage of strncpy and strncat in i8042_pnp_kbd_probe(); drivers/input/serio/i8042-x86ia64io.h
Date: Mon, 05 Nov 2007 23:30:58 +0100 [thread overview]
Message-ID: <472F99A2.9080209@tiscali.nl> (raw)
In-Reply-To: <d120d5000711051308p62094becnce4fdb57cb30687a@mail.gmail.com>
Dmitry Torokhov wrote:
> Hi Roel,
>
> On Nov 5, 2007 3:24 PM, Roel Kluin <12o3l@tiscali.nl> wrote:
>> See http://www.gratisoft.us/todd/papers/strlcpy.html
>> --
>> Fix incorrect length argument for strncpy and strncat by replacing them with
>
> What is incorrect about the argument?
As explained in the article, strncpy and strncat should not get sizeof(target) as a
third argument, but rather, for strncpy 'sizeof(target) -1' and for strncat
'sizeof(target) - strlen(target) - 1'.
for strlcpy and strlcat sizeof(target) should be used. Also strncpy and strncat
zero out the remainder of the characters - if source is shorter than target - which
makes it slower than the strl- variants.
> I will gladly take a patch replacing strncat with strlcat but don't
> error out if the buffer is too small - it is oK if PNP name is printed
> truncated, it does not affect KBC operations.
Ok, updated patch below.
--
Fix incorrect length argument for strncpy and strncat by replacing them with
strlcpy and strlcat
Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index f8fe421..1a739cf 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -297,10 +297,10 @@ static int i8042_pnp_kbd_probe(struct pnp_dev *dev, const struct pnp_device_id *
if (pnp_irq_valid(dev,0))
i8042_pnp_kbd_irq = pnp_irq(dev, 0);
- strncpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name));
+ strlcpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name));
if (strlen(pnp_dev_name(dev))) {
- strncat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name));
- strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
+ strlcat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name));
+ strlcat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
}
i8042_pnp_kbd_devices++;
@@ -318,10 +318,10 @@ static int i8042_pnp_aux_probe(struct pnp_dev *dev, const struct pnp_device_id *
if (pnp_irq_valid(dev, 0))
i8042_pnp_aux_irq = pnp_irq(dev, 0);
- strncpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name));
+ strlcpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name));
if (strlen(pnp_dev_name(dev))) {
- strncat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name));
- strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
+ strlcat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name));
+ strlcat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
}
i8042_pnp_aux_devices++;
prev parent reply other threads:[~2007-11-05 22:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-05 20:24 [PATCH] Fix incorrect usage of strncpy and strncat in i8042_pnp_kbd_probe(); drivers/input/serio/i8042-x86ia64io.h Roel Kluin
2007-11-05 21:08 ` Dmitry Torokhov
2007-11-05 22:30 ` Roel Kluin [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=472F99A2.9080209@tiscali.nl \
--to=12o3l@tiscali.nl \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@atrey.karlin.mff.cuni.cz \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.