Linux console tools development discussion
 help / color / mirror / Atom feed
From: Felix Janda <felix.janda@posteo.de>
To: Linux console tools development discussion <kbd@lists.altlinux.org>
Subject: Re: [kbd] Invalid out of bounds memory read when running make check
Date: Sun, 27 Mar 2016 20:59:22 +0100
Message-ID: <20160327195922.GA13409@nyan> (raw)
In-Reply-To: <20160321104152.654b0d38@pc1>

Subject: ksyms: Fix out of bounds memory read in codetoksym

Bug detected by Hanno Böck using asan.
---
 src/libkeymap/ksyms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libkeymap/ksyms.c b/src/libkeymap/ksyms.c
index 22b1336..3d35ead 100644
--- a/src/libkeymap/ksyms.c
+++ b/src/libkeymap/ksyms.c
@@ -197,7 +197,7 @@ codetoksym(struct lk_ctx *ctx, int code) {
 		i = ctx->charset;
 		while (1) {
 			p = (sym *) charsets[i].charnames;
-			if (p) {
+			if (p && (KVAL(code) >= charsets[i].start)) {
 				p += KVAL(code) - charsets[i].start;
 
 				if (p->name[0])
-- 
2.7.3

Hanno Böck wrote:
> Hi,
> 
> When compiling kbd (latest version 2.0.3) with address sanitizer and
> running the test suite (make check) it will show a global out of bounds
> memory read. I have attached the address sanitizer error message at the
> end of this mail.
> 
> I have not fully tracked down the bug, but the error happens in the
> file ksyms.c in line 203.
> 
> The test that's causing this can be manually run with
> ./libkeymap-dumpkeys ./dumpkeys.ua-ws.map SEPARATE_LINE FALSE
> in the tests dir.
> 
> This line from dumpkeys.ua-ws.map causes it:
> altgr keycode   3 = 157
> 
> To reproduce:
> ./configure CFLAGS="-fsanitize=address -g" LDFLAGS="-fsanitize=address"
> make
> make check

It segfaults for me on a musl based system without asan. I think that
the patch above should fix it.

Felix


  reply	other threads:[~2016-03-27 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21  9:41 Hanno Böck
2016-03-27 19:59 ` Felix Janda [this message]
2016-04-02 16:36   ` Alexey Gladkov

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=20160327195922.GA13409@nyan \
    --to=felix.janda@posteo.de \
    --cc=kbd@lists.altlinux.org \
    /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

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