Skip to content

Commit

Permalink
reading lines which have a length greater than BUFSIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Jan 22, 2024
1 parent e5fc1ac commit 52ff29e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/getfilecontents.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ econf_err
read_file(econf_file *ef, const char *file,
const char *delim, const char *comment)
{
char buf[BUFSIZ];
char *current_group = NULL;
char *current_comment_before_key = NULL;
char *current_comment_after_value = NULL;
Expand All @@ -265,12 +264,13 @@ read_file(econf_file *ef, const char *file,
}
ef->delimiter = *delim;

while (fgets(buf, BUFSIZ-1, kf)) {
char *buf = malloc(BUFSIZ*sizeof(char));
size_t max_size = BUFSIZ;
while (getline(&buf, &max_size, kf) >0) {
char *p, *name, *data = NULL;
bool quote_seen = false, delim_seen = false;
char *org_buf __attribute__ ((__cleanup__(free_buffer))) = strdup(buf);

buf[BUFSIZ-1] = '\0';
line++;
last_scanned_line_nr = line;

Expand Down Expand Up @@ -301,8 +301,10 @@ read_file(econf_file *ef, const char *file,
char *content = current_comment_before_key;
int ret = asprintf(&current_comment_before_key, "%s\n%s", content,
p+1);
if(ret<0)
if(ret<0) {
free(buf);
return ECONF_NOMEM;
}
free(content);
} else {
current_comment_before_key = strdup(p+1);
Expand All @@ -315,8 +317,10 @@ read_file(econf_file *ef, const char *file,
char *content = current_comment_after_value;
int ret = asprintf(&current_comment_after_value, "%s\n%s", content,
p+1);
if(ret<0)
if(ret<0) {
free(buf);
return ECONF_NOMEM;
}
free(content);
} else {
current_comment_after_value = strdup(p+1);
Expand Down Expand Up @@ -516,6 +520,7 @@ read_file(econf_file *ef, const char *file,
}

out:
free(buf);
fclose (kf);
if (current_group)
free (current_group);
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(TESTS tst-filedoesnotexit1
tst-arguments5
tst-string
tst-string-append
tst-long-name
tst-security
tst-checkfiles
tst-delimiter-comment
Expand Down
2 changes: 2 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ tst_string_exe = executable('tst-string', 'tst-string.c', c_args: test_args, dep
test('tst-string', tst_string_exe)
tst_string_append_exe = executable('tst-string-append', 'tst-string-append.c', c_args: test_args, dependencies : libeconf_dep)
test('tst-string-append', tst_string_append_exe)
tst_long_name_exe = executable('tst-long-name', 'tst-long-name.c', c_args: test_args, dependencies : libeconf_dep)
test('tst-long-name', tst_long_name_exe)
tst_security_exe = executable('tst-security', 'tst-security.c', c_args: test_args, dependencies : libeconf_dep)
test('tst-security', tst_security_exe)
tst_checkfiles_exe = executable('tst-checkfiles', 'tst-checkfiles.c', c_args: test_args, dependencies : libeconf_dep)
Expand Down
1 change: 1 addition & 0 deletions tests/tst-long-name/test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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