From 3e0fee42ade3ec27c5e659bc45fa5a7ef3231474 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Thu, 11 Sep 2003 21:38:03 +0000 Subject: [PATCH] * slerr.c (SLang_doerror): Fix possible off-by-one error. * sltermin.c (_SLtt_tigetent): Likewise. --- slang/ChangeLog | 5 +++++ slang/slerr.c | 13 +++++++------ slang/sltermin.c | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/slang/ChangeLog b/slang/ChangeLog index e231b17d5..8eddd4c09 100644 --- a/slang/ChangeLog +++ b/slang/ChangeLog @@ -1,3 +1,8 @@ +2003-09-11 Andrew V. Samoilov + + * slerr.c (SLang_doerror): Fix possible off-by-one error. + * sltermin.c (_SLtt_tigetent): Likewise. + 2002-11-28 Pavel Roskin * sldisply.c: Fix for the previous patch. Only swap colors if diff --git a/slang/slerr.c b/slang/slerr.c index 43486f429..896392a56 100644 --- a/slang/slerr.c +++ b/slang/slerr.c @@ -78,24 +78,25 @@ void SLang_doerror (char *error) else { char *sle = "S-Lang Error: "; - unsigned int len; - char *fmt; + unsigned int len = 0; + char *fmt = "%s%s%s"; str = get_error_string (); - fmt = "%s%s%s"; if ((error == NULL) || (*error == 0)) error = ""; else if (SLang_Error == SL_UNKNOWN_ERROR) /* Do not display an unknown error message if error is non-NULL */ str = ""; - else + else { fmt = "%s%s: %s"; + len = 2; /* ": " */ + } - len = strlen (sle) + strlen (str) + strlen(error) + 1; + len += strlen (sle) + strlen (str) + strlen(error) + 1 /* trailing 0 */; err = err_buf; - if (len >= sizeof (err_buf)) + if (len > sizeof (err_buf)) { if (NULL == (malloced_err_buf = SLmalloc (len))) err = NULL; diff --git a/slang/sltermin.c b/slang/sltermin.c index 7ae525925..598421902 100644 --- a/slang/sltermin.c +++ b/slang/sltermin.c @@ -283,7 +283,7 @@ SLterminfo_Type *_SLtt_tigetent (char *term) if (*tidir == 0) break; /* last one */ - if (sizeof (file) > strlen (tidir) + 2 + strlen (term)) + if (sizeof (file) >= strlen (tidir) + 4 + strlen (term)) { sprintf (file, "%s/%c/%s", tidir, *term, term); if (NULL != (fp = open_terminfo (file, ti)))