summaryrefslogtreecommitdiff
path: root/sbin/isakmpd/conf.c
diff options
context:
space:
mode:
authorHakan Olsson <ho@cvs.openbsd.org>2002-04-22 12:52:40 +0000
committerHakan Olsson <ho@cvs.openbsd.org>2002-04-22 12:52:40 +0000
commit7668729272b92ce230302713e97f3c1e2ad71339 (patch)
tree1826504cf47a541a8e5bb29f543c4920343c455e /sbin/isakmpd/conf.c
parent2dfb382e6a22275013c84ddb43a8f482dd2bb99c (diff)
Handle configuration lines that end in whitespace or ^M.
Also avoid a potential memory leak.
Diffstat (limited to 'sbin/isakmpd/conf.c')
-rw-r--r--sbin/isakmpd/conf.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/sbin/isakmpd/conf.c b/sbin/isakmpd/conf.c
index 25eca2859e7..655eb6c7549 100644
--- a/sbin/isakmpd/conf.c
+++ b/sbin/isakmpd/conf.c
@@ -1,9 +1,9 @@
-/* $OpenBSD: conf.c,v 1.37 2002/03/01 14:54:20 ho Exp $ */
+/* $OpenBSD: conf.c,v 1.38 2002/04/22 12:52:39 ho Exp $ */
/* $EOM: conf.c,v 1.48 2000/12/04 02:04:29 angelos Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Niklas Hallqvist. All rights reserved.
- * Copyright (c) 2000, 2001 Håkan Olsson. All rights reserved.
+ * Copyright (c) 2000, 2001, 2002 Håkan Olsson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -223,7 +223,7 @@ conf_set_now (char *section, char *tag, char *value, int override,
static void
conf_parse_line (int trans, char *line, size_t sz)
{
- char *cp = line;
+ char *val;
int i;
static char *section = 0;
static int ln = 0;
@@ -240,6 +240,8 @@ conf_parse_line (int trans, char *line, size_t sz)
for (i = 1; i < sz; i++)
if (line[i] == ']')
break;
+ if (section)
+ free (section);
if (i == sz)
{
log_print ("conf_parse_line: %d:"
@@ -247,16 +249,19 @@ conf_parse_line (int trans, char *line, size_t sz)
section = 0;
return;
}
- if (section)
- free (section);
section = malloc (i);
+ if (!section)
+ {
+ log_print ("conf_parse_line: %d: malloc (%d) failed", ln, i);
+ return;
+ }
strlcpy (section, line + 1, i);
return;
}
/* Deal with assignments. */
for (i = 0; i < sz; i++)
- if (cp[i] == '=')
+ if (line[i] == '=')
{
/* If no section, we are ignoring the lines. */
if (!section)
@@ -266,9 +271,13 @@ conf_parse_line (int trans, char *line, size_t sz)
return;
}
line[strcspn (line, " \t=")] = '\0';
+ val = line + i + 1 + strspn (line + i + 1, " \t");
+ /* Skip trailing whitespace, if any */
+ i = strcspn (val, " \t\r");
+ if (i)
+ val[i] = '\0';
/* XXX Perhaps should we not ignore errors? */
- conf_set (trans, section, line,
- line + i + 1 + strspn (line + i + 1, " \t"), 0, 0);
+ conf_set (trans, section, line, val, 0, 0);
return;
}