diff options
author | c | 2024-01-28 21:43:37 -0500 |
---|---|---|
committer | c | 2024-01-28 21:43:37 -0500 |
commit | ca20ff4f4d0ac63856e538f9f4cef97197bf6465 (patch) | |
tree | ba8886c8832e082332a284e3b18fb0e4bbce3d05 /src/source.c | |
parent | 422606d8b3cc6fba74f97af46f0378fc274d60ad (diff) |
Fixed buffer-overflow.
Diffstat (limited to 'src/source.c')
-rw-r--r-- | src/source.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/source.c b/src/source.c index f7f7063..813e9f5 100644 --- a/src/source.c +++ b/src/source.c @@ -1,5 +1,5 @@ #include "include/source.h" -#include <unistd.h> + char* source_get(char* arg) { return arg? source_get_from_fpath(arg): @@ -30,19 +30,20 @@ char* source_get_from_fpath(char* path) { } char* source_get_from_stdin() { + char* s; char* src; size_t l; - src = ecalloc(256, sizeof(char)); l = 0; - while (fgets(src + l, 20, stdin) != NULL) { - l += strlen(src + l); - } + src = ecalloc(16, sizeof(char)); - (src[l - 1] == '\n') && (src[l - 1] = '\0'); + while ((s = fgets(src + l, 20, stdin))) { + l = MIN(16, l + strlen(src + l)); + } -// src = fgets(src, 256, stdin); + /* This works, I guess. */ + s && src[l - 1] == '\n' && (src[l - 1] = '\0'); return src; } |