Fail gracefully on failure to find component include If we can't find the component of the include file we're looking for, make sure we don't return success when we meant failure, segfault, or spectacularly leak everything. Tested with incorrect component includes for keycodes, compat, symbols, and types. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Reported-by: David Herrmann <dh.herrmann@googlemail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
diff --git a/src/malloc.c b/src/malloc.c
index f63cf2c..80ebc69 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -346,10 +346,12 @@ XkbcFreeClientMap(struct xkb_desc * xkb)
}
free(map->types);
- for (key = xkb->min_key_code; key < xkb->max_key_code; key++) {
- free(map->key_sym_map[key].sym_index);
- free(map->key_sym_map[key].num_syms);
- free(map->key_sym_map[key].syms);
+ if (map->key_sym_map) {
+ for (key = xkb->min_key_code; key < xkb->max_key_code; key++) {
+ free(map->key_sym_map[key].sym_index);
+ free(map->key_sym_map[key].num_syms);
+ free(map->key_sym_map[key].syms);
+ }
}
free(map->key_sym_map);
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index df6fd36..3518902 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -46,7 +46,7 @@ CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge)
unsigned required, legal;
unsigned mainType;
const char *mainName;
- LEDInfo *unbound = NULL;
+ LEDInfo *unbound = NULL, *next;
struct xkb_desc *xkb = XkbcAllocKeyboard(context);
struct {
XkbFile *keycodes;
@@ -159,25 +159,25 @@ CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge)
}
/* compile the sections we have in the file one-by-one, or fail. */
- if (sections.keycodes != NULL &&
+ if (sections.keycodes == NULL ||
!CompileKeycodes(sections.keycodes, xkb, MergeOverride))
{
ERROR("Failed to compile keycodes\n");
goto err;
}
- if (sections.types != NULL &&
+ if (sections.types == NULL ||
!CompileKeyTypes(sections.types, xkb, MergeOverride))
{
ERROR("Failed to compile key types\n");
goto err;
}
- if (sections.compat != NULL &&
+ if (sections.compat == NULL ||
!CompileCompatMap(sections.compat, xkb, MergeOverride, &unbound))
{
ERROR("Failed to compile compat map\n");
goto err;
}
- if (sections.symbols != NULL &&
+ if (sections.symbols == NULL ||
!CompileSymbols(sections.symbols, xkb, MergeOverride))
{
ERROR("Failed to compile symbols\n");
@@ -200,5 +200,10 @@ err:
ACTION("Failed to compile keymap\n");
if (xkb)
xkb_map_unref(xkb);
+ while (unbound) {
+ next = (LEDInfo *) unbound->defs.next;
+ free(unbound);
+ unbound = next;
+ }
return NULL;
}
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index dfced04..9605324 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -954,10 +954,15 @@ HandleIncludeSymbols(IncludeStmt * stmt,
else
{
info->errorCount += 10;
+ FreeSymbolsInfo(&included);
return False;
}
}
}
+ else if (stmt->next)
+ {
+ info->errorCount += included.errorCount;
+ }
if (haveSelf)
*info = included;
else
@@ -2183,7 +2188,7 @@ CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
if (info.nKeys == 0) {
FreeSymbolsInfo(&info);
- return True;
+ return False;
}
if (info.errorCount == 0)