Commit Graph

7 Commits (master)

Author SHA1 Message Date
Pierre Le Marre e325e65eb8 Add test_unit to all tests
Currently it only ensure we do not buffer `stdout`.
2024-02-21 06:26:36 +01:00
Pierre Le Marre 00e3058e7b Prevent recursive includes of keymap components
- Add check for recursive includes of keymap components. It relies on
  limiting the include depth. The threshold is currently to 15, which
  seems reasonable with plenty of margin for keymaps in the wild.
- Add corresponding new log message `recursive-include`.
- Add tests for recursive includes.
2023-11-06 22:06:25 +01:00
Pierre Le Marre 82e9293e12 xkbcomp: early detection of invalid encoding 2023-11-03 04:16:50 +01:00
Pierre Le Marre f937c30820 xkbcomp: skip heading UTF-8 encoded BOM (U+FEFF)
Leading BOM is legal and is used as a signature — an indication that
an otherwise unmarked text file is in UTF-8.
See: https://www.unicode.org/faq/utf_bom.html#bom5 for further
details.
2023-10-30 07:15:13 +01:00
Peter Hutterer b06aedb8ba scanner: allow for a zero terminated string as keymap
As the documentation for xkb_keymap_new_from_buffer() states, the "input string
does not have to be zero-terminated". The actual implementation however failed
with "unrecognized token/syntax error" when it encountered a null byte.

Fix this by allowing a null byte at the last position of the buffer. Anything
else is likely a client error anyway.

Fixes #307
2023-05-05 09:57:23 +10:00
Ran Benita 40aab05e77 build: include config.h manually
Previously we included it with an `-include` compiler directive. But
that's not portable. And it's better to be explicit anyway.

Every .c file should have `include "config.h"` first thing.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:09:11 +02:00
David Herrmann 36f55c494e keymap: add xkb_keymap_new_from_buffer()
The current API doesn't allow the caller to create keymaps from mmap()'ed
files. The problem is, xkb_keymap_new_from_string() requires a terminating
0 byte. However, there is no way to guarantee that when using mmap() so a
user currently has to copy the whole file just to get the terminating zero
byte (assuming they cannot use xkb_keymap_new_from_file()).

This adds a new entry xkb_keymap_new_from_buffer() which takes a memory
location and the buffer size in bytes.

Internally, we depend on yy_scan_{string,byte}() helpers. According to
flex documentation these already copy the input string because they are
wrappers around yy_scan_buffer().
yy_scan_buffer() on the other hand has some insane requirements. The
buffer must be writeable and the last two bytes must be ASCII-NUL. But the
buffer may contain other 0 bytes just fine.

Because we don't want these constraints in our public API,
xkb_keymap_new_from_buffer() needs to create a copy of the input memory.
But it then calls yy_scan_buffer() directly. Hence, we have the same
number of buffer-copies as with *_from_string() but without the
terminating 0 requirement.
The explicit yy_scan_buffer() call is preferred over yy_scan_byte() so the
buffer-copy operation is not hidden somewhere in flex.

Maybe some day we no longer depend on flex and can have a zero-copy API. A
user could mmap() a file and it would get parsed right from this buffer.
But until then, we shouldn't expose this limitation in the API but instead
provide an API that some day can work with zero-copy.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

[ran: rebased on top of my branch]
Conflicts:
	Makefile.am
	src/xkbcomp/xkbcomp.c
2013-04-01 18:04:06 +01:00