Fixed memory handling in cString::Append()

This commit is contained in:
Klaus Schmidinger 2020-06-10 20:52:10 +02:00
parent 8a282ef267
commit 5cfa736ad0
3 changed files with 13 additions and 7 deletions

View File

@ -3510,6 +3510,7 @@ Stefan Herdler <herdler@gmx.de>
too early
for reporting a bug in using the default sort mode in a video directory without a
".sort" file
for reporting faulty memory handling in cString::Append()
Tobias Faust <tobias.faust@gmx.de>
for the original "jumpingseconds" patch

View File

@ -9462,3 +9462,4 @@ Video Disk Recorder Revision History
indicate this change.
- Added a device hook for detecting whether a device provides EIT data (thanks to
Winfried Köhler).
- Fixed memory handling in cString::Append() (reported by Stefan Herdler).

18
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 4.11 2018/03/04 10:28:04 kls Exp $
* $Id: tools.c 4.12 2020/06/10 20:52:10 kls Exp $
*/
#include "tools.h"
@ -1099,12 +1099,16 @@ cString &cString::operator=(const char *String)
cString &cString::Append(const char *String)
{
int l1 = strlen(s);
int l2 = strlen(String);
char *p = (char *)realloc(s, l1 + l2 + 1);
if (p != s)
strcpy(p, s);
strcpy(p + l1, String);
if (String) {
int l1 = s ? strlen(s) : 0;
int l2 = strlen(String);
if (char *p = (char *)realloc(s, l1 + l2 + 1)) {
s = p;
strcpy(s + l1, String);
}
else
esyslog("ERROR: out of memory");
}
return *this;
}