summaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authorGravatar default2023-07-11 19:45:58 +0200
committerGravatar default2023-07-11 19:45:58 +0200
commit1c5a6894579924cb4d35e41ba3f140797a89c083 (patch)
tree839d36778afd953a18b1203f160c8ffc99949365 /xs.h
parentMerge pull request 'Attempt to prevent XSS.' (#64) from yonle/snac2:master in... (diff)
downloadsnac2-1c5a6894579924cb4d35e41ba3f140797a89c083.tar.gz
snac2-1c5a6894579924cb4d35e41ba3f140797a89c083.tar.xz
snac2-1c5a6894579924cb4d35e41ba3f140797a89c083.zip
Fixed some memory leaks.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h15
1 files changed, 0 insertions, 15 deletions
diff --git a/xs.h b/xs.h
index 6bf3eb8..ad8a35d 100644
--- a/xs.h
+++ b/xs.h
@@ -72,7 +72,6 @@ xs_str *xs_replace_in(xs_str *str, const char *sfrom, const char *sto, int times
72xs_str *xs_fmt(const char *fmt, ...); 72xs_str *xs_fmt(const char *fmt, ...);
73int xs_str_in(const char *haystack, const char *needle); 73int xs_str_in(const char *haystack, const char *needle);
74int _xs_startsorends(const char *str, const char *xfix, int ends); 74int _xs_startsorends(const char *str, const char *xfix, int ends);
75xs_str *xs_encode_html(const xs_str *str);
76#define xs_startswith(str, prefix) _xs_startsorends(str, prefix, 0) 75#define xs_startswith(str, prefix) _xs_startsorends(str, prefix, 0)
77#define xs_endswith(str, postfix) _xs_startsorends(str, postfix, 1) 76#define xs_endswith(str, postfix) _xs_startsorends(str, postfix, 1)
78xs_str *xs_crop_i(xs_str *str, int start, int end); 77xs_str *xs_crop_i(xs_str *str, int start, int end);
@@ -507,20 +506,6 @@ int _xs_startsorends(const char *str, const char *xfix, int ends)
507 return !!(ssz >= psz && memcmp(xfix, str + (ends ? ssz - psz : 0), psz) == 0); 506 return !!(ssz >= psz && memcmp(xfix, str + (ends ? ssz - psz : 0), psz) == 0);
508} 507}
509 508
510xs_str *xs_encode_html(const char *str)
511/* escapes html characters */
512{
513 xs_str *encoded = xs_replace(str, "&", "&");
514 encoded = xs_replace(encoded, "<", "&lt;");
515 encoded = xs_replace(encoded, ">", "&gt;");
516 encoded = xs_replace(encoded, "\"", "&#34;");
517 encoded = xs_replace(encoded, "'", "&#39;");
518
519 // Restore only <br>. Probably safe. Let's hope nothing goes wrong with this.
520 encoded = xs_replace(encoded, "&lt;br&gt;", "<br>");
521
522 return encoded;
523}
524 509
525xs_str *xs_crop_i(xs_str *str, int start, int end) 510xs_str *xs_crop_i(xs_str *str, int start, int end)
526/* crops the d_char to be only from start to end */ 511/* crops the d_char to be only from start to end */