summaryrefslogtreecommitdiff
path: root/src/rc/rc.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-01-07 12:29:30 +0000
committerRoy Marples <roy@marples.name>2008-01-07 12:29:30 +0000
commit43d0f3fc76542d0859c9b84402c0483a22e02b68 (patch)
tree125bcc9bf644a6390718868312df2b6be1905e89 /src/rc/rc.c
parent74e0e58b899accd2bd72a7d7303331e47089959f (diff)
downloadopenrc-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.c')
-rw-r--r--src/rc/rc.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/rc/rc.c b/src/rc/rc.c
index 6874efc..c94bf11 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);