summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/io/config.c18
-rw-r--r--src/packet/record.c15
2 files changed, 27 insertions, 6 deletions
diff --git a/src/io/config.c b/src/io/config.c
index 36afbef..bf9d96a 100644
--- a/src/io/config.c
+++ b/src/io/config.c
@@ -32,9 +32,20 @@ static bool get_words(char* buf, char** words, int count) {
int offset = 0;
int i = 0;
- for(i = 0; i < count; i++) {
+ while(1) {
char c;
- while(c = buf[offset], c != ' ' && c != '\0' && c != '\n') {
+ while(1) {
+ if (offset == MAX_LEN) return false;
+ c = buf[offset];
+
+ if (c == '\0' || c == '\n') {
+ break;
+ }
+
+ if (c == ' ' && i + 1 != count) {
+ break;
+ }
+
offset++;
}
@@ -48,8 +59,11 @@ static bool get_words(char* buf, char** words, int count) {
if (c == '\0' || c == '\n') {
break;
+ } else if (i + 1 == count) {
+ break;
}
+ i++;
}
return i + 1 == count;
}
diff --git a/src/packet/record.c b/src/packet/record.c
index a21d852..53934ed 100644
--- a/src/packet/record.c
+++ b/src/packet/record.c
@@ -357,8 +357,12 @@ static void write_caa_record(PacketBuffer* buffer, CAARecord* data) {
static void write_string(TXTRecord* record, uint8_t* capacity, const char* string, uint8_t len) {
if (len < 1) return;
- if (record->len == *capacity) {
- *capacity *= 2;
+ if (record->len >= *capacity) {
+ if (*capacity >= 128) {
+ *capacity = 255;
+ } else {
+ *capacity *= 2;
+ }
record->text = realloc(record->text, sizeof(uint8_t*) * *capacity);
}
record->text[record->len] = malloc(len + 1);
@@ -394,8 +398,11 @@ static void write_cmd_record(PacketBuffer* buffer, CMDRecord* data) {
int i = 0;
while (1) {
- if ((c = getc(output)) == EOF) {
- write_string(&res, &capacity, in, i + 1);
+ if (res.len >= 255) break;
+
+ c = getc(output);
+ if (c == EOF || c == '\0') {
+ write_string(&res, &capacity, in, i);
break;
}