From 6f42ccbce41012b8903ef41f6dbcea306344b5f8 Mon Sep 17 00:00:00 2001 From: Jun-ichiro itojun Hagino Date: Mon, 9 Dec 2002 07:23:53 +0000 Subject: better parsing of # comments. from provos --- bin/systrace/policy.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'bin/systrace') diff --git a/bin/systrace/policy.c b/bin/systrace/policy.c index fbdb57e22d7..6daf5957a9c 100644 --- a/bin/systrace/policy.c +++ b/bin/systrace/policy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: policy.c,v 1.22 2002/12/09 07:22:53 itojun Exp $ */ +/* $OpenBSD: policy.c,v 1.23 2002/12/09 07:23:52 itojun Exp $ */ /* * Copyright 2002 Niels Provos * All rights reserved. @@ -481,18 +481,26 @@ static char * systrace_policyline(char *line) { char *p; + int quoted = 0; if ((p = strchr(line, '\n')) == NULL) return (NULL); *p = '\0'; - /* Remove comments from the input line */ - p = strchr(line, '#'); - if (p != NULL) { - if (p != line && *(p-1) == '-') - p = strchr(p + 1, '#'); - if (p != NULL) + /* Remove comments from the input line but ignore # that are part + * of the system call name or within quotes. + */ + for (p = line; *p; p++) { + if (*p == '"') + quoted = quoted ? 0 : 1; + if (*p == '#') { + if (quoted) + continue; + if (p != line && *(p-1) == '-') + continue; *p = '\0'; + break; + } } /* Remove trailing white space */ -- cgit v1.2.3