Linux console tools development discussion
 help / color / mirror / Atom feed
* [kbd] [PATCH] libkeymap: Fix mk_mapname for the plain map
@ 2019-12-06 15:58 Javier Pello García
  2020-02-23 17:36 ` Alexey Gladkov
  0 siblings, 1 reply; 2+ messages in thread
From: Javier Pello García @ 2019-12-06 15:58 UTC (permalink / raw)
  To: kbd

mk_mapname did not correctly return "plain" for the plain map
(no modifier set) if it had already been called, as it did not
correctly reset the static buffer that it uses for the map name.
When mk_mapname is called for the first time from the first loop
in lk_dump_ctable, all is fine, since buf has not been used yet
and it is initialised to 0. However, when it is called again for
the plain map from the second loop in lk_dump_ctable, buf already
contains a value (left over from the last iteration in the first
loop), and then strcat appends "plain" to that value instead of
overwriting it, resulting in a bogus value.

Signed-off-by: Javier Pello <javier.pello@urjc.es>
---
 src/libkeymap/dump.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/libkeymap/dump.c b/src/libkeymap/dump.c
index 8531b5aa..02c8eab4 100644
--- a/src/libkeymap/dump.c
+++ b/src/libkeymap/dump.c
@@ -91,7 +91,7 @@ fail:
 	return -1;
 }
 
-static char *
+static const char *
 mk_mapname(char modifier)
 {
 	static const char *mods[8] = {
@@ -100,10 +100,8 @@ mk_mapname(char modifier)
 	static char buf[60];
 	int i;
 
-	if (!modifier) {
-		strcat(buf, "plain");
-		return buf;
-	}
+	if (!modifier)
+		return "plain";
 	buf[0] = 0;
 	for (i = 0; i < 8; i++)
 		if (modifier & (1 << i)) {
-- 
2.23.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [kbd] [PATCH] libkeymap: Fix mk_mapname for the plain map
  2019-12-06 15:58 [kbd] [PATCH] libkeymap: Fix mk_mapname for the plain map Javier Pello García
@ 2020-02-23 17:36 ` Alexey Gladkov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Gladkov @ 2020-02-23 17:36 UTC (permalink / raw)
  To: Linux console tools development discussion

On Fri, Dec 06, 2019 at 03:58:03PM +0000, Javier Pello García wrote:
> mk_mapname did not correctly return "plain" for the plain map
> (no modifier set) if it had already been called, as it did not
> correctly reset the static buffer that it uses for the map name.
> When mk_mapname is called for the first time from the first loop
> in lk_dump_ctable, all is fine, since buf has not been used yet
> and it is initialised to 0. However, when it is called again for
> the plain map from the second loop in lk_dump_ctable, buf already
> contains a value (left over from the last iteration in the first
> loop), and then strcat appends "plain" to that value instead of
> overwriting it, resulting in a bogus value.

Thanks for report. To fix this, it is enough to replace strcat with
strcpy. Fixed. Thanks!

-- 
Rgrds, legion



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-23 17:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 15:58 [kbd] [PATCH] libkeymap: Fix mk_mapname for the plain map Javier Pello García
2020-02-23 17:36 ` Alexey Gladkov

Linux console tools development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/kbd/0 kbd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kbd kbd/ http://lore.altlinux.org/kbd \
		kbd@lists.altlinux.org kbd@lists.altlinux.ru kbd@lists.altlinux.com
	public-inbox-index kbd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.kbd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git