aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-21 15:31:48 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-21 15:31:48 +0100
commit91d9f33e86b39737617d2d3fbc016673ba3b8cb1 (patch)
treef9be548a41b33d921fa8ff0ead5a56a6a0d9bce1 /src
parent24d6fe7ee9d2362a199323d083d58bcdfe84df69 (diff)
downloadrspamd-91d9f33e86b39737617d2d3fbc016673ba3b8cb1.tar.gz
rspamd-91d9f33e86b39737617d2d3fbc016673ba3b8cb1.zip
Fix some issues with comments in rcl.
Diffstat (limited to 'src')
-rw-r--r--src/rcl/rcl_parser.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/rcl/rcl_parser.c b/src/rcl/rcl_parser.c
index cf7384019..90202b6c5 100644
--- a/src/rcl/rcl_parser.c
+++ b/src/rcl/rcl_parser.c
@@ -84,48 +84,49 @@ rspamd_cl_skip_comments (struct rspamd_cl_parser *parser, GError **err)
parser->state != RSPAMD_RCL_STATE_MCOMMENT) {
while (p < chunk->end) {
if (*p == '\n') {
- rspamd_cl_chunk_skipc (chunk, *p);
+ rspamd_cl_chunk_skipc (chunk, *++p);
break;
}
- rspamd_cl_chunk_skipc (chunk, *p);
- p ++;
+ rspamd_cl_chunk_skipc (chunk, *++p);
}
}
}
else if (*p == '/' && chunk->remain >= 2) {
- p ++;
+ rspamd_cl_chunk_skipc (chunk, *++p);
if (*p == '/' && parser->state != RSPAMD_RCL_STATE_SCOMMENT &&
parser->state != RSPAMD_RCL_STATE_MCOMMENT) {
chunk->pos = p;
while (p < chunk->end) {
if (*p == '\n') {
- rspamd_cl_chunk_skipc (chunk, *p);
+ rspamd_cl_chunk_skipc (chunk, *++p);
break;
}
- rspamd_cl_chunk_skipc (chunk, *p);
- p ++;
+ rspamd_cl_chunk_skipc (chunk, *++p);
}
}
else if (*p == '*') {
comments_nested ++;
- chunk->pos = p;
+ rspamd_cl_chunk_skipc (chunk, *++p);
while (p < chunk->end) {
if (*p == '*') {
- rspamd_cl_chunk_skipc (chunk, *p);
- p ++;
- rspamd_cl_chunk_skipc (chunk, *p);
+ rspamd_cl_chunk_skipc (chunk, *++p);
if (*p == '/') {
comments_nested --;
if (comments_nested == 0) {
+ rspamd_cl_chunk_skipc (chunk, *++p);
break;
}
}
- p ++;
- rspamd_cl_chunk_skipc (chunk, *p);
+ rspamd_cl_chunk_skipc (chunk, *++p);
}
- rspamd_cl_chunk_skipc (chunk, *p);
- p ++;
+ else if (p[0] == '/' && chunk->remain >= 2 && p[1] == '*') {
+ comments_nested ++;
+ rspamd_cl_chunk_skipc (chunk, *++p);
+ rspamd_cl_chunk_skipc (chunk, *++p);
+ continue;
+ }
+ rspamd_cl_chunk_skipc (chunk, *++p);
}
if (comments_nested != 0) {
rspamd_cl_set_err (chunk, RSPAMD_CL_ENESTED, "comments nesting is invalid", err);
@@ -213,6 +214,20 @@ rspamd_cl_lex_is_atom_end (const guchar c)
return FALSE;
}
+static inline gboolean
+rspamd_cl_lex_is_comment (const guchar c1, const guchar c2)
+{
+ if (c1 == '/') {
+ if (c2 == '/' || c2 == '*') {
+ return TRUE;
+ }
+ }
+ else if (c1 == '#') {
+ return TRUE;
+ }
+ return FALSE;
+}
+
/**
* Parse possible number
* @param parser
@@ -623,7 +638,7 @@ rspamd_cl_parse_key (struct rspamd_cl_parser *parser,
return FALSE;
}
}
- else if ((p[0] == '/' && p[1] == '/') || *p == '#') {
+ else if (rspamd_cl_lex_is_comment (p[0], p[1])) {
/* Check for comment */
if (!rspamd_cl_skip_comments (parser, err)) {
return FALSE;
@@ -772,7 +787,7 @@ rspamd_cl_parse_value (struct rspamd_cl_parser *parser, struct rspamd_cl_chunk *
default:
/* Skip any spaces and comments */
if (g_ascii_isspace (*p) ||
- (p[0] == '/' && p[1] == '/') || *p == '#') {
+ rspamd_cl_lex_is_comment (p[0], p[1])) {
while (p < chunk->end && g_ascii_isspace (*p)) {
rspamd_cl_chunk_skipc (chunk, *p);
p ++;
@@ -845,11 +860,13 @@ rspamd_cl_parse_after_value (struct rspamd_cl_parser *parser, struct rspamd_cl_c
rspamd_cl_chunk_skipc (chunk, *p);
p ++;
}
- else if ((p[0] == '/' && p[1] == '/') || *p == '#') {
+ else if (rspamd_cl_lex_is_comment (p[0], p[1])) {
/* Skip comment */
if (!rspamd_cl_skip_comments (parser, err)) {
return FALSE;
}
+ /* Treat comment as a separator */
+ got_sep = TRUE;
p = chunk->pos;
}
else if (*p == ',') {
@@ -1131,7 +1148,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
/* Now we need to skip all spaces */
while (p < chunk->end) {
if (!g_ascii_isspace (*p)) {
- if ((p[0] == '/' && p[1] == '/') || *p == '#') {
+ if (rspamd_cl_lex_is_comment (p[0], p[1])) {
/* Skip comment */
if (!rspamd_cl_skip_comments (parser, err)) {
return FALSE;