summaryrefslogtreecommitdiff
path: root/src/librc/librc-depend.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/librc/librc-depend.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/librc/librc-depend.c')
-rw-r--r--src/librc/librc-depend.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index 0ce95e6..aece385 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -124,7 +124,7 @@ rc_depinfo_t *rc_deptree_load (void)
rc_depinfo_t *deptree = NULL;
rc_depinfo_t *depinfo = NULL;
rc_deptype_t *deptype = NULL;
- char buffer [RC_LINEBUFFER];
+ char *line;
char *type;
char *p;
char *e;
@@ -133,26 +133,26 @@ rc_depinfo_t *rc_deptree_load (void)
if (! (fp = fopen (RC_DEPTREE, "r")))
return (NULL);
- while (fgets (buffer, RC_LINEBUFFER, fp))
+ while ((line = rc_getline (fp)))
{
- p = buffer;
+ p = line;
e = strsep (&p, "_");
if (! e || strcmp (e, "depinfo") != 0)
- continue;
+ goto next;
e = strsep (&p, "_");
if (! e || sscanf (e, "%d", &i) != 1)
- continue;
+ goto next;
if (! (type = strsep (&p, "_=")))
- continue;
+ goto next;
if (strcmp (type, "service") == 0)
{
/* Sanity */
e = get_shell_value (p);
if (! e || strlen (e) == 0)
- continue;
+ goto next;
if (! deptree)
{
@@ -167,17 +167,17 @@ rc_depinfo_t *rc_deptree_load (void)
memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = xstrdup (e);
deptype = NULL;
- continue;
+ goto next;
}
e = strsep (&p, "=");
if (! e || sscanf (e, "%d", &i) != 1)
- continue;
+ goto next;
/* Sanity */
e = get_shell_value (p);
if (! e || strlen (e) == 0)
- continue;
+ goto next;
if (! deptype)
{
@@ -197,6 +197,9 @@ rc_depinfo_t *rc_deptree_load (void)
deptype->type = xstrdup (type);
rc_strlist_addsort (&deptype->services, e);
+
+next:
+ free (line);
}
fclose (fp);
@@ -722,7 +725,7 @@ bool rc_deptree_update (void)
rc_deptype_t *deptype = NULL;
rc_deptype_t *dt;
rc_deptype_t *last_deptype = NULL;
- char *buffer = NULL;
+ char *line;
int len;
int i;
int j;
@@ -740,20 +743,14 @@ bool rc_deptree_update (void)
deptree = xmalloc (sizeof (rc_depinfo_t));
memset (deptree, 0, sizeof (rc_depinfo_t));
- buffer = xmalloc (sizeof (char) * RC_LINEBUFFER);
- memset (buffer, 0, RC_LINEBUFFER);
/* Phase 2 */
- while (fgets (buffer, RC_LINEBUFFER, fp))
+ while ((line = rc_getline (fp)))
{
- /* Trim the newline */
- if (buffer[strlen (buffer) - 1] == '\n')
- buffer[strlen(buffer) -1] = 0;
-
- depends = buffer;
+ depends = line;
service = strsep (&depends, " ");
if (! service)
- continue;
+ goto next;
type = strsep (&depends, " ");
for (depinfo = deptree; depinfo; depinfo = depinfo->next)
@@ -778,7 +775,7 @@ bool rc_deptree_update (void)
/* We may not have any depends */
if (! type || ! depends)
- continue;
+ goto next;
/* Get the type */
if (strcmp (type, "config") != 0) {
@@ -844,9 +841,11 @@ bool rc_deptree_update (void)
rc_strlist_delete (&dt->services, depend);
}
}
+
+next:
+ free (line);
}
pclose (fp);
- free (buffer);
/* Phase 3 - add our providors to the tree */
for (depinfo = deptree; depinfo; depinfo = depinfo->next)