added buffer overflow check
This commit is contained in:
parent
b0884bf41a
commit
5b3923141f
1 changed files with 9 additions and 2 deletions
|
@ -26,17 +26,18 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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 "sys/log.h"
|
||||||
#include "lib/simEnvChange.h"
|
#include "lib/simEnvChange.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX_LOG_LENGTH 1024
|
||||||
const struct simInterface simlog_interface;
|
const struct simInterface simlog_interface;
|
||||||
|
|
||||||
// COOJA variables
|
// COOJA variables
|
||||||
char simLoggedData[1024];
|
char simLoggedData[MAX_LOG_LENGTH];
|
||||||
int simLoggedLength;
|
int simLoggedLength;
|
||||||
char simLoggedFlag;
|
char simLoggedFlag;
|
||||||
|
|
||||||
|
@ -53,6 +54,12 @@ log_message(const char *part1, const char *part2)
|
||||||
void
|
void
|
||||||
simlog(const char *message)
|
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));
|
memcpy(&simLoggedData[0] + simLoggedLength, &message[0], strlen(message));
|
||||||
simLoggedLength += strlen(message);
|
simLoggedLength += strlen(message);
|
||||||
simLoggedFlag = 1;
|
simLoggedFlag = 1;
|
||||||
|
|
Loading…
Reference in a new issue