Commit 19e3e6cd authored by Justin Stitt's avatar Justin Stitt Committed by Greg Kroah-Hartman
Browse files

accessibility: speakup: refactor deprecated strncpy

`strncpy` is deprecated for use on NUL-terminated destination strings [1].

Let's refactor this function to just use synth_write().

Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90


Cc: linux-hardening@vger.kernel.org
Signed-off-by: default avatarJustin Stitt <justinstitt@google.com>
Suggested-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Tested-by: default avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
Link: https://lore.kernel.org/r/20230918-strncpy-drivers-accessibility-speakup-kobjects-c-v2-1-d5b1976c5dbf@google.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2953fa03
Loading
Loading
Loading
Loading
+11 −14
Original line number Diff line number Diff line
@@ -413,27 +413,24 @@ static ssize_t synth_direct_store(struct kobject *kobj,
				  struct kobj_attribute *attr,
				  const char *buf, size_t count)
{
	u_char tmp[256];
	int len;
	int bytes;
	const char *ptr = buf;
	char *unescaped;
	unsigned long flags;

	if (!synth)
		return -EPERM;

	len = strlen(buf);
	unescaped = kstrdup(buf, GFP_KERNEL);
	if (!unescaped)
		return -ENOMEM;

	string_unescape_any_inplace(unescaped);

	spin_lock_irqsave(&speakup_info.spinlock, flags);
	while (len > 0) {
		bytes = min_t(size_t, len, 250);
		strncpy(tmp, ptr, bytes);
		tmp[bytes] = '\0';
		string_unescape_any_inplace(tmp);
		synth_printf("%s", tmp);
		ptr += bytes;
		len -= bytes;
	}
	synth_write(unescaped, strlen(unescaped));
	spin_unlock_irqrestore(&speakup_info.spinlock, flags);

	kfree(unescaped);

	return count;
}