From 82745b5e7bb83fd3a0f32a1f57c056610297a7ff Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Mon, 12 Apr 2010 12:49:57 -0600 Subject: [PATCH] bti: fix a crash for echo -n|bti My previous patch was not thought out completely and so the new bti crashes if fed an input without a newline, like this: echo -n "status test" | bti The obvious fix seems the most appropriate approach in this case. Signed-off-by: Pete Zaitcev Signed-off-by: Greg Kroah-Hartman --- bti.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bti.c b/bti.c index 02b8aea..c0c5804 100644 --- a/bti.c +++ b/bti.c @@ -144,7 +144,8 @@ static char *get_string(const char *name) if (!fgets(string, 999, stdin)) return NULL; temp = strchr(string, '\n'); - *temp = '\0'; + if (temp) + *temp = '\0'; return string; } @@ -749,7 +750,8 @@ static char *get_string_from_stdin(void) if (!fgets(string, 999, stdin)) return NULL; temp = strchr(string, '\n'); - *temp = '\0'; + if (temp) + *temp = '\0'; return string; } -- 2.39.5