From 43d0f3fc76542d0859c9b84402c0483a22e02b68 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 7 Jan 2008 12:29:30 +0000 Subject: 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. --- src/rc/rc.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/rc/rc.c') diff --git a/src/rc/rc.c b/src/rc/rc.c index 6874efce..c94bf11f 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -479,7 +479,7 @@ static int do_shell_var (int argc, char **argv) static char *proc_getent (const char *ent) { FILE *fp; - char *buffer; + char *proc; char *p; char *value = NULL; int i; @@ -492,18 +492,11 @@ static char *proc_getent (const char *ent) return (NULL); } - buffer = xmalloc (sizeof (char) * RC_LINEBUFFER); - memset (buffer, 0, RC_LINEBUFFER); - if (fgets (buffer, RC_LINEBUFFER, fp) && - (p = strstr (buffer, ent))) + if ((proc = rc_getline (fp)) && + (p = strstr (proc, ent))) { - i = p - buffer; - if (i == '\0' || buffer[i - 1] == ' ') { - /* Trim the trailing carriage return if present */ - i = strlen (buffer) - 1; - if (buffer[i] == '\n') - buffer[i] = 0; - + i = p - proc; + if (i == '\0' || proc[i - 1] == ' ') { p += strlen (ent); if (*p == '=') p++; @@ -511,7 +504,7 @@ static char *proc_getent (const char *ent) } } else errno = ENOENT; - free (buffer); + free (proc); fclose (fp); return (value); -- cgit v1.2.3