Download scripts/escape_trace.diff from shawnnnliu/Hardened_SEC-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/datasets/shawnnnliu/Hardened_SEC-Bench/resolve/main/scripts/escape_trace.diff
- Command line
-
hf download hf://datasets/shawnnnliu/Hardened_SEC-Bench/scripts/escape_trace.diff
-
curl -L -o escape_trace.diff https://huggingface.co/datasets/shawnnnliu/Hardened_SEC-Bench/resolve/main/scripts/escape_trace.diff
2.95 kB
| diff --git a/programs/escape.c b/programs/escape.c | |
| --- a/programs/escape.c | |
| +++ b/programs/escape.c | |
| #include "common.h" | |
| #include "escape.h" | |
| +/* ESCAPE-TRACE (scripts/escape_trace.diff, instrumentation only): append one | |
| + * line per call to /tmp/escape_trace.log with the number of examined | |
| + * characters of each class and of buffer growths. Changes no result. */ | |
| +static void | |
| +escape_trace (const char *func, int sp, int hi, int pl, int ct, int grow) | |
| +{ | |
| + FILE *f = fopen ("/tmp/escape_trace.log", "a"); | |
| + if (!f) | |
| + return; | |
| + fprintf (f, "ESCAPE-TRACE %s in=%d special=%d high=%d plain=%d ctl=%d grow=%d\n", | |
| + func, sp + hi + pl + ct, sp, hi, pl, ct, grow); | |
| + fclose (f); | |
| +} | |
| +#define ESCAPE_COUNT(c, sp, hi, pl, ct) \ | |
| + do \ | |
| + { \ | |
| + if ((c) >= 127) \ | |
| + hi++; \ | |
| + else if ((c) == 34 || (c) == 39 || (c) == 38 || (c) == 60 || (c) == 62 \ | |
| + || (c) == 96 || (c) == 123 || (c) == 125) \ | |
| + sp++; \ | |
| + else if ((c) >= 20) \ | |
| + pl++; \ | |
| + else \ | |
| + ct++; \ | |
| + } \ | |
| + while (0) | |
| + | |
| char * ATTRIBUTE_MALLOC | |
| htmlescape (const char *restrict src, const int cp) | |
| { | |
| int len; | |
| char *dest, *d, *end; | |
| unsigned char *s; | |
| + int nsp = 0, nhi = 0, npl = 0, nct = 0, ngrow = 0; | |
| if (!src) | |
| return NULL; | |
| len = strlen (src) + 10; | |
| d = dest + off; | |
| *d = 0; | |
| end = dest + len; | |
| + ngrow++; | |
| } | |
| + ESCAPE_COUNT (*s, nsp, nhi, npl, nct); | |
| switch (*s) | |
| { | |
| case '"': | |
| s++; | |
| } | |
| *d = 0; | |
| + escape_trace ("htmlescape", nsp, nhi, npl, nct, ngrow); | |
| return dest; | |
| } | |
| char *dest, *d; | |
| BITCODE_TU tmp = wstr; | |
| BITCODE_RS c; | |
| + int nsp = 0, nhi = 0, npl = 0, nct = 0, ngrow = 0; | |
| if (!wstr) | |
| return NULL; | |
| len += 16; | |
| dest = realloc (dest, len); | |
| d = dest + off; | |
| + ngrow++; | |
| } | |
| + ESCAPE_COUNT (*wstr, nsp, nhi, npl, nct); | |
| switch (*wstr) | |
| { | |
| case 34: strcat (d, """); d += 6; break; | |
| } | |
| } | |
| *d = 0; | |
| + escape_trace ("htmlwescape", nsp, nhi, npl, nct, ngrow); | |
| return dest; | |
| } | |