]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.146/staging-speakup-replace-strncpy-with-memcpy.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.146 / staging-speakup-replace-strncpy-with-memcpy.patch
1 From fd29edc7232bc19f969e8f463138afc5472b3d5f Mon Sep 17 00:00:00 2001
2 From: Guenter Roeck <linux@roeck-us.net>
3 Date: Sun, 1 Jul 2018 13:57:24 -0700
4 Subject: staging: speakup: Replace strncpy with memcpy
5
6 From: Guenter Roeck <linux@roeck-us.net>
7
8 commit fd29edc7232bc19f969e8f463138afc5472b3d5f upstream.
9
10 gcc 8.1.0 generates the following warnings.
11
12 drivers/staging/speakup/kobjects.c: In function 'punc_store':
13 drivers/staging/speakup/kobjects.c:522:2: warning:
14 'strncpy' output truncated before terminating nul
15 copying as many bytes from a string as its length
16 drivers/staging/speakup/kobjects.c:504:6: note: length computed here
17
18 drivers/staging/speakup/kobjects.c: In function 'synth_store':
19 drivers/staging/speakup/kobjects.c:391:2: warning:
20 'strncpy' output truncated before terminating nul
21 copying as many bytes from a string as its length
22 drivers/staging/speakup/kobjects.c:388:8: note: length computed here
23
24 Using strncpy() is indeed less than perfect since the length of data to
25 be copied has already been determined with strlen(). Replace strncpy()
26 with memcpy() to address the warning and optimize the code a little.
27
28 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
29 Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32
33 ---
34 drivers/staging/speakup/kobjects.c | 4 ++--
35 1 file changed, 2 insertions(+), 2 deletions(-)
36
37 --- a/drivers/staging/speakup/kobjects.c
38 +++ b/drivers/staging/speakup/kobjects.c
39 @@ -387,7 +387,7 @@ static ssize_t synth_store(struct kobjec
40 len = strlen(buf);
41 if (len < 2 || len > 9)
42 return -EINVAL;
43 - strncpy(new_synth_name, buf, len);
44 + memcpy(new_synth_name, buf, len);
45 if (new_synth_name[len - 1] == '\n')
46 len--;
47 new_synth_name[len] = '\0';
48 @@ -517,7 +517,7 @@ static ssize_t punc_store(struct kobject
49 return -EINVAL;
50 }
51
52 - strncpy(punc_buf, buf, x);
53 + memcpy(punc_buf, buf, x);
54
55 while (x && punc_buf[x - 1] == '\n')
56 x--;