diff --git a/lib/getfilecontents.c b/lib/getfilecontents.c index 5949552..4cd3753 100644 --- a/lib/getfilecontents.c +++ b/lib/getfilecontents.c @@ -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; @@ -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; @@ -301,8 +301,10 @@ read_file(econf_file *ef, const char *file, char *content = current_comment_before_key; int ret = asprintf(¤t_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); @@ -315,8 +317,10 @@ read_file(econf_file *ef, const char *file, char *content = current_comment_after_value; int ret = asprintf(¤t_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); @@ -516,6 +520,7 @@ read_file(econf_file *ef, const char *file, } out: + free(buf); fclose (kf); if (current_group) free (current_group); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9f92074..00512e5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 diff --git a/tests/meson.build b/tests/meson.build index bfff28f..00f9998 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -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) diff --git a/tests/tst-long-name/test.conf b/tests/tst-long-name/test.conf new file mode 100644 index 0000000..f5c027f --- /dev/null +++ b/tests/tst-long-name/test.conf @@ -0,0 +1 @@ +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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