diff options
| author | 2023-03-07 09:56:16 +0100 | |
|---|---|---|
| committer | 2023-03-07 09:56:16 +0100 | |
| commit | 2250ad702723a50afd93def3735fcfe854701aa3 (patch) | |
| tree | 44c34fbf2ff7f0d93ece6c5c842cdbd27eb498f3 | |
| parent | is_msg_for_me() also accepts msgs where a followed is cc'ed. (diff) | |
| download | penes-snac2-2250ad702723a50afd93def3735fcfe854701aa3.tar.gz penes-snac2-2250ad702723a50afd93def3735fcfe854701aa3.tar.xz penes-snac2-2250ad702723a50afd93def3735fcfe854701aa3.zip | |
Sanitize control codes in JSON code.
| -rw-r--r-- | format.c | 9 | ||||
| -rw-r--r-- | xs_json.h | 4 |
2 files changed, 5 insertions, 8 deletions
| @@ -179,15 +179,8 @@ 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); | ||
| 183 | 182 | ||
| 184 | /* strip dangerous control codes */ | 183 | sl = xs_regex_split(content, "</?[^>]+>"); |
| 185 | for (n = 0; content2[n]; n++) { | ||
| 186 | if (xs_type(&content2[n]) != XSTYPE_STRING) | ||
| 187 | content2[n] = ' '; | ||
| 188 | } | ||
| 189 | |||
| 190 | sl = xs_regex_split(content2, "</?[^>]+>"); | ||
| 191 | 184 | ||
| 192 | p = sl; | 185 | p = sl; |
| 193 | 186 | ||
| @@ -260,6 +260,10 @@ static xs_val *_xs_json_loads_lexer(const char **json, js_type *t) | |||
| 260 | else | 260 | else |
| 261 | cp = i; | 261 | cp = i; |
| 262 | 262 | ||
| 263 | /* replace dangerous control codes with the replacement char */ | ||
| 264 | if (cp >= '\0' && cp < ' ' && !strchr("\r\n\t", cp)) | ||
| 265 | cp = 0xfffd; | ||
| 266 | |||
| 263 | v = xs_utf8_enc(v, cp); | 267 | v = xs_utf8_enc(v, cp); |
| 264 | c = '\0'; | 268 | c = '\0'; |
| 265 | 269 | ||