- Subject: [slang-devel] Fixes for issues found by static analysis
- From: Miroslav Lichvar <mlichvar@xxxxxxxxxx>
- Date: Wed, 25 Jul 2018 13:45:28 +0200
Hi,
I'm attaching patches for some issues reported by the Coverity tool.
It reported also a bunch of memory leaks, but I wasn't sure which are
actually valid bugs. Please let me know if you would like more
details.
--
Miroslav Lichvar
From d338fd6e949ef62e7eac4eb5c024059e02158b06 Mon Sep 17 00:00:00 2001
From: Miroslav Lichvar <mlichvar@xxxxxxxxxx>
Date: Wed, 25 Jul 2018 13:07:42 +0200
Subject: [PATCH 1/2] Replaced memcpy in SLang_getkey
memcpy() is not defined for overlapping buffers, i.e. it may copy bytes
in any direction. As SLMEMMOVE is not defined in slang, replace the
SLMEMCPY call with a for loop.
---
src/slgetkey.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/slgetkey.c b/src/slgetkey.c
index 86e7946..d9bc678 100644
--- a/src/slgetkey.c
+++ b/src/slgetkey.c
@@ -40,13 +40,13 @@ unsigned int SLang_getkey (void)
if (SLang_Input_Buffer_Len)
{
- unsigned int imax;
+ unsigned int i, imax;
ch = (unsigned int) *SLang_Input_Buffer;
SLang_Input_Buffer_Len--;
imax = SLang_Input_Buffer_Len;
- SLMEMCPY ((char *) SLang_Input_Buffer,
- (char *) (SLang_Input_Buffer + 1), imax);
+ for (i = 0; i < imax; i++)
+ SLang_Input_Buffer[i] = SLang_Input_Buffer[i + 1];
}
else if (SLANG_GETKEY_ERROR == (ch = _pSLsys_getkey ())) return ch;
--
2.17.1
From 1ae6dc551c4d4b38de03ed05f3e73ba7026b0fbf Mon Sep 17 00:00:00 2001
From: Miroslav Lichvar <mlichvar@xxxxxxxxxx>
Date: Wed, 25 Jul 2018 13:12:57 +0200
Subject: [PATCH 2/2] Added missing return statement in intrin_putenv()
Avoid saving a pointer that has been freed.
---
src/slstd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/slstd.c b/src/slstd.c
index eaf5236..552d812 100644
--- a/src/slstd.c
+++ b/src/slstd.c
@@ -214,6 +214,7 @@ static void intrin_putenv (void) /*{{{*/
{
SLang_set_error (SL_OS_Error);
SLfree (s);
+ return;
}
/* Note that s is NOT freed */
--
2.17.1
[2018 date index]
[2018 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]