Fix a crash caused by having a single NULL character as a string capability.

This fix is about the best we can do given the current interfaces. We
could extend the cgetcap(3) interfaces with a function that would return
a character count and handle this in libterm which would provide a more
complete fix and allow a NULL character in a string capability.
This commit is contained in:
blymn 2007-08-28 12:28:18 +00:00
parent 6ae9cab127
commit 2b4f2c9caf
1 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: getch.c,v 1.48 2007/05/28 15:01:55 blymn Exp $ */
/* $NetBSD: getch.c,v 1.49 2007/08/28 12:28:18 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: getch.c,v 1.48 2007/05/28 15:01:55 blymn Exp $");
__RCSID("$NetBSD: getch.c,v 1.49 2007/08/28 12:28:18 blymn Exp $");
#endif
#endif /* not lint */
@ -396,6 +396,19 @@ add_key_sequence(SCREEN *screen, char *sequence, int key_type)
* base keymap. */
length = (int) strlen(sequence);
/*
* OK - we really should never get a zero length string here, either
* the termcap entry is there and it has a value or we are not called
* at all. Unfortunately, if someone assigns a termcap string to the
* ^@ value we get passed a null string which messes up our length.
* So, if we get a null string then just insert a leaf value in
* the 0th char position of the root keymap. Note that we are
* totally screwed if someone terminates a multichar sequence
* with ^@... oh well.
*/
if (length == 0)
length = 1;
for (j = 0; j < length - 1; j++) {
/* add the entry to the struct */
tmp_key = add_new_key(current, sequence[j], KEYMAP_MULTI, 0);