summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-02-26 08:27:04 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-02-26 08:27:04 -0800
commitf4904fc17335144026b8825ee9ef19f7dc4e7ded (patch)
tree64b880fc0ea45f0d80fb2134e0eb42718613ae5d
parentf12e5ee270b7def53dd42ffe1efa099737f241ab (diff)
downloadtxr-f4904fc17335144026b8825ee9ef19f7dc4e7ded.tar.gz
txr-f4904fc17335144026b8825ee9ef19f7dc4e7ded.tar.bz2
txr-f4904fc17335144026b8825ee9ef19f7dc4e7ded.zip
linenoise: defensive null pointer check.
* linenoise/linenoise.c (move_cursor_multiline): If the npos argument happens to be equal to the current position (the operation is a null move), then no movement is generated. In that case, no ab_append operation is called, and ab.b will stay null; this null pointer then gets passed to lino_os.puts_fn as the string to output, and that will blow up. This situation hasn't actually been observed.
-rw-r--r--linenoise/linenoise.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index cb4b9f41..50e44e00 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -1272,7 +1272,8 @@ static void move_cursor_multiline(lino_t *l, int npos)
ab_append(&ab, seq, wcslen(seq));
}
- (void) lino_os.puts_fn(l->tty_ofs, ab.b);
+ if (ab.b)
+ (void) lino_os.puts_fn(l->tty_ofs, ab.b);
ab_free(&ab);
l->dpos = npos;
l->oldrow = nrow;