diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-11 22:57:42 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-11 22:57:42 +0100 |
commit | c6673ac3149c172056cfa13ec6818b8113aada0d (patch) | |
tree | 4c53262b3add2eea0da810a6391d70bfa093664b | |
parent | 735f159a64d302681f8a836ad538ed399bbf7b28 (diff) | |
download | rspamd-c6673ac3149c172056cfa13ec6818b8113aada0d.tar.gz rspamd-c6673ac3149c172056cfa13ec6818b8113aada0d.zip |
[Fix] Parse rgb[a](x,x,x[,x]) css colors
-rw-r--r-- | src/libserver/html.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/libserver/html.c b/src/libserver/html.c index 6b18ee784..77f777ee2 100644 --- a/src/libserver/html.c +++ b/src/libserver/html.c @@ -1731,6 +1731,112 @@ rspamd_html_process_color (const gchar *line, guint len, struct html_color *cl) cl->d.val = strtoul (hexbuf, NULL, 16); cl->valid = TRUE; } + else if (len > 4 && rspamd_lc_cmp (p, "rgb", 3) == 0) { + /* We have something like rgba(x,x,x,x) or rgb(x,x,x) */ + enum { + obrace, + num1, + num2, + num3, + skip_spaces + } state = skip_spaces, next_state = obrace; + gulong r = 0, g = 0, b = 0; + const gchar *c; + gboolean valid = FALSE; + + p += 3; + + if (*p == 'a') { + p ++; + } + + c = p; + + while (p < end) { + switch (state) { + case obrace: + if (*p == '(') { + p ++; + state = skip_spaces; + next_state = num1; + } + else if (g_ascii_isspace (*p)) { + state = skip_spaces; + next_state = obrace; + } + else { + goto stop; + } + break; + case num1: + if (*p == ',') { + if (!rspamd_strtoul (c, p - c, &r)) { + goto stop; + } + + p ++; + state = skip_spaces; + next_state = num2; + } + else if (!g_ascii_isdigit (*p)) { + goto stop; + } + else { + p ++; + } + break; + case num2: + if (*p == ',') { + if (!rspamd_strtoul (c, p - c, &g)) { + goto stop; + } + + p ++; + state = skip_spaces; + next_state = num3; + } + else if (!g_ascii_isdigit (*p)) { + goto stop; + } + else { + p ++; + } + break; + case num3: + if (*p == ',') { + if (!rspamd_strtoul (c, p - c, &b)) { + goto stop; + } + + valid = TRUE; + goto stop; + } + else if (!g_ascii_isdigit (*p)) { + goto stop; + } + else { + p ++; + } + break; + case skip_spaces: + if (!g_ascii_isspace (*p)) { + c = p; + state = next_state; + } + else { + p ++; + } + break; + } + } + + stop: + + if (valid) { + cl->d.val = b + (g << 8) + (r << 16); + cl->valid = TRUE; + } + } else { /* Compare color by name */ search.begin = line; |