diff options
| author | 2023-03-06 11:06:35 +0100 | |
|---|---|---|
| committer | 2023-03-06 11:06:35 +0100 | |
| commit | 49f2f498de0ad3b2c8df1203ff444c1794617ecb (patch) | |
| tree | 2186b34f807ee238770f799ba4a290ea9716577b /format.c | |
| parent | Reject MUTEd actor messages ASAP with a 403 status. (diff) | |
| download | penes-snac2-49f2f498de0ad3b2c8df1203ff444c1794617ecb.tar.gz penes-snac2-49f2f498de0ad3b2c8df1203ff444c1794617ecb.tar.xz penes-snac2-49f2f498de0ad3b2c8df1203ff444c1794617ecb.zip | |
Strip dangerous control codes in sanitize().
Diffstat (limited to 'format.c')
| -rw-r--r-- | format.c | 11 |
1 files changed, 10 insertions, 1 deletions
| @@ -179,11 +179,20 @@ d_char *sanitize(const char *content) | |||
| 179 | xs *sl; | 179 | xs *sl; |
| 180 | int n = 0; | 180 | int n = 0; |
| 181 | char *p, *v; | 181 | char *p, *v; |
| 182 | xs *content2 = xs_dup(content); | ||
| 182 | 183 | ||
| 183 | sl = xs_regex_split(content, "</?[^>]+>"); | 184 | /* strip dangerous control codes */ |
| 185 | for (n = 0; content2[n]; n++) { | ||
| 186 | if (content2[n] > 0x0 && content2[n] < 0x20 && | ||
| 187 | content2[n] != '\r' && content2[n] != '\n') | ||
| 188 | content2[n] = ' '; | ||
| 189 | } | ||
| 190 | |||
| 191 | sl = xs_regex_split(content2, "</?[^>]+>"); | ||
| 184 | 192 | ||
| 185 | p = sl; | 193 | p = sl; |
| 186 | 194 | ||
| 195 | n = 0; | ||
| 187 | while (xs_list_iter(&p, &v)) { | 196 | while (xs_list_iter(&p, &v)) { |
| 188 | if (n & 0x1) { | 197 | if (n & 0x1) { |
| 189 | xs *s1 = xs_strip_i(xs_crop_i(xs_dup(v), v[1] == '/' ? 2 : 1, -1)); | 198 | xs *s1 = xs_strip_i(xs_crop_i(xs_dup(v), v[1] == '/' ? 2 : 1, -1)); |