diff options
author | Roy Marples <roy@marples.name> | 2008-01-07 12:29:30 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-01-07 12:29:30 +0000 |
commit | 43d0f3fc76542d0859c9b84402c0483a22e02b68 (patch) | |
tree | 125bcc9bf644a6390718868312df2b6be1905e89 /src/rc/rc-misc.c | |
parent | 74e0e58b899accd2bd72a7d7303331e47089959f (diff) | |
download | openrc-43d0f3fc76542d0859c9b84402c0483a22e02b68.tar.gz openrc-43d0f3fc76542d0859c9b84402c0483a22e02b68.tar.bz2 openrc-43d0f3fc76542d0859c9b84402c0483a22e02b68.tar.xz |
rc_getline keeps expanding it's malloced buffer until it has read a whole line or EOF. All functions which read into static buffers have been changed to use fhis function to avoid any potential overflows and to ensure we really do read a long long config line.
Diffstat (limited to 'src/rc/rc-misc.c')
-rw-r--r-- | src/rc/rc-misc.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index 85d7cd7..79db432 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -238,7 +238,7 @@ char **env_filter (void) static bool file_regex (const char *file, const char *regex) { FILE *fp; - char *buffer; + char *line; regex_t re; bool retval = false; int result; @@ -246,23 +246,22 @@ static bool file_regex (const char *file, const char *regex) if (! (fp = fopen (file, "r"))) return (false); - buffer = xmalloc (sizeof (char) * RC_LINEBUFFER); if ((result = regcomp (&re, regex, REG_EXTENDED | REG_NOSUB)) != 0) { fclose (fp); - regerror (result, &re, buffer, RC_LINEBUFFER); - fprintf (stderr, "file_regex: %s", buffer); - free (buffer); + line = xmalloc (sizeof (char) * BUFSIZ); + regerror (result, &re, line, BUFSIZ); + fprintf (stderr, "file_regex: %s", line); + free (line); return (false); } - while (fgets (buffer, RC_LINEBUFFER, fp)) { - if (regexec (&re, buffer, 0, NULL, 0) == 0) - { + while ((line = rc_getline (fp))) { + if (regexec (&re, line, 0, NULL, 0) == 0) retval = true; + free (line); + if (retval) break; - } } - free (buffer); fclose (fp); regfree (&re); |