diff mbox

[iproute2,v2,2/2] arpd: fix parsing of unlikely long comments

Message ID 1451846374-2665-2-git-send-email-andreas@fatal.se
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Andreas Henriksson Jan. 3, 2016, 6:39 p.m. UTC
In case the commented out line was longer than the buffer size,
the remaining part was previously not properly skipped.

With this fix we should now continue ignoring lines starting with #
until we find a newline character.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
---
 misc/arpd.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Andreas Henriksson Jan. 3, 2016, 6:44 p.m. UTC | #1
Hello Stephen Hemminger.

Please beware that this has been compile-tested only.
Submitting it like this was what I was trying to avoid
by just throwing in a FIXME comment in the initial submission.
Sorry in advance if I managed to screw something up, but
hopefully I didn't...

Regards,
Andreas Henriksson

On Sun, Jan 03, 2016 at 07:39:33PM +0100, Andreas Henriksson wrote:
> In case the commented out line was longer than the buffer size,
> the remaining part was previously not properly skipped.
> 
> With this fix we should now continue ignoring lines starting with #
> until we find a newline character.
> 
> Signed-off-by: Andreas Henriksson <andreas@fatal.se>
> ---
>  misc/arpd.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/misc/arpd.c b/misc/arpd.c
> index 700dc50..a4f0f0d 100644
> --- a/misc/arpd.c
> +++ b/misc/arpd.c
> @@ -691,6 +691,7 @@ int main(int argc, char **argv)
>  		FILE *fp;
>  		struct dbkey k;
>  		DBT dbkey, dbdat;
> +		int skip_until_eol = 0;
>  
>  		dbkey.data = &k;
>  		dbkey.size = sizeof(k);
> @@ -707,8 +708,19 @@ int main(int argc, char **argv)
>  			char ipbuf[128];
>  			char macbuf[128];
>  
> -			if (buf[0] == '#')
> +			/* skip remaining part of commented outline. */
> +			if (skip_until_eol) {
> +				if (strrchr(buf, '\n') != NULL)
> +					skip_until_eol = 0;
>  				continue;
> +			}
> +
> +			/* skip (beginning of) commented out line. */
> +			if (buf[0] == '#') {
> +				if (strrchr(buf, '\n') == NULL)
> +					skip_until_eol = 1;
> +				continue;
> +			}
>  
>  			if (sscanf(buf, "%u%s%s", &k.iface, ipbuf, macbuf) != 3) {
>  				fprintf(stderr, "Wrong format of input file \"%s\"\n", do_load);
> -- 
> 2.1.4
> 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stephen Hemminger Jan. 3, 2016, 11:04 p.m. UTC | #2
On Sun, 3 Jan 2016 19:44:29 +0100
Andreas Henriksson <andreas@fatal.se> wrote:

> Hello Stephen Hemminger.
> 
> Please beware that this has been compile-tested only.
> Submitting it like this was what I was trying to avoid
> by just throwing in a FIXME comment in the initial submission.
> Sorry in advance if I managed to screw something up, but
> hopefully I didn't...
> 
> Regards,
> Andreas Henriksson
> 

All this seems like overkill. The file format for arpd is very simple:
ifindex, IPv4, MAC
and really should never be too long. If it is the input is garbage and the
whole input should just be rejected, logged, and arpd should exit.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/misc/arpd.c b/misc/arpd.c
index 700dc50..a4f0f0d 100644
--- a/misc/arpd.c
+++ b/misc/arpd.c
@@ -691,6 +691,7 @@  int main(int argc, char **argv)
 		FILE *fp;
 		struct dbkey k;
 		DBT dbkey, dbdat;
+		int skip_until_eol = 0;
 
 		dbkey.data = &k;
 		dbkey.size = sizeof(k);
@@ -707,8 +708,19 @@  int main(int argc, char **argv)
 			char ipbuf[128];
 			char macbuf[128];
 
-			if (buf[0] == '#')
+			/* skip remaining part of commented outline. */
+			if (skip_until_eol) {
+				if (strrchr(buf, '\n') != NULL)
+					skip_until_eol = 0;
 				continue;
+			}
+
+			/* skip (beginning of) commented out line. */
+			if (buf[0] == '#') {
+				if (strrchr(buf, '\n') == NULL)
+					skip_until_eol = 1;
+				continue;
+			}
 
 			if (sscanf(buf, "%u%s%s", &k.iface, ipbuf, macbuf) != 3) {
 				fprintf(stderr, "Wrong format of input file \"%s\"\n", do_load);