From 7dad625926f1249386d4630b57f8e7f1a5059195 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 22 Oct 2015 14:38:01 -0500 Subject: Add nulls during reading of settings and info files Change-Id: Ie6202a8cc709d8593768f447ef95b4a815605d6b --- data.cpp | 4 +++- infomanager.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data.cpp b/data.cpp index 7d923838e..9f2e6b5cb 100644 --- a/data.cpp +++ b/data.cpp @@ -274,16 +274,18 @@ int DataManager::LoadValues(const string filename) string Name; string Value; unsigned short length; - char array[512]; + char array[513]; if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; if (length >= 512) goto error; if (fread(array, 1, length, in) != length) goto error; + array[length+1] = '\0'; Name = array; if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; if (length >= 512) goto error; if (fread(array, 1, length, in) != length) goto error; + array[length+1] = '\0'; Value = array; map::iterator pos; diff --git a/infomanager.cpp b/infomanager.cpp index 864c431a5..2a4c3c892 100644 --- a/infomanager.cpp +++ b/infomanager.cpp @@ -67,16 +67,18 @@ int InfoManager::LoadValues(void) { string Name; string Value; unsigned short length; - char array[512]; + char array[513]; if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; if (length >= 512) goto error; if (fread(array, 1, length, in) != length) goto error; + array[length+1] = '\0'; Name = array; if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; if (length >= 512) goto error; if (fread(array, 1, length, in) != length) goto error; + array[length+1] = '\0'; Value = array; map::iterator pos; -- cgit v1.2.3