added buffer overflow check
This commit is contained in:
parent
b0884bf41a
commit
5b3923141f
@ -26,17 +26,18 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: log.c,v 1.1 2006/08/21 12:11:20 fros4943 Exp $
|
||||
* $Id: log.c,v 1.2 2007/05/15 18:13:32 fros4943 Exp $
|
||||
*/
|
||||
|
||||
#include "sys/log.h"
|
||||
#include "lib/simEnvChange.h"
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_LOG_LENGTH 1024
|
||||
const struct simInterface simlog_interface;
|
||||
|
||||
// COOJA variables
|
||||
char simLoggedData[1024];
|
||||
char simLoggedData[MAX_LOG_LENGTH];
|
||||
int simLoggedLength;
|
||||
char simLoggedFlag;
|
||||
|
||||
@ -53,6 +54,12 @@ log_message(const char *part1, const char *part2)
|
||||
void
|
||||
simlog(const char *message)
|
||||
{
|
||||
if (simLoggedLength + strlen(message) > MAX_LOG_LENGTH) {
|
||||
/* Dropping message due to buffer overflow */
|
||||
printf("Warning. Dropping log message due to buffer overflow\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&simLoggedData[0] + simLoggedLength, &message[0], strlen(message));
|
||||
simLoggedLength += strlen(message);
|
||||
simLoggedFlag = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user