labels now allow underscored; bug fix
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include "../src/tinytemplate.h"
|
||||
|
||||
/* this lets the source compile without afl-clang-fast/lto */
|
||||
#ifndef __AFL_FUZZ_TESTCASE_LEN
|
||||
|
||||
ssize_t fuzz_len;
|
||||
unsigned char fuzz_buf[1024000];
|
||||
|
||||
#define __AFL_FUZZ_TESTCASE_LEN fuzz_len
|
||||
#define __AFL_FUZZ_TESTCASE_BUF fuzz_buf
|
||||
//#define __AFL_FUZZ_INIT() void sync(void);
|
||||
//#define __AFL_LOOP(x) ((fuzz_len = read(0, fuzz_buf, sizeof(fuzz_buf))) > 0 ? 1 : 0)
|
||||
//#define __AFL_INIT() sync()
|
||||
|
||||
#endif
|
||||
|
||||
__AFL_FUZZ_INIT();
|
||||
|
||||
//#pragma clang optimize off
|
||||
//#pragma GCC optimize("O0")
|
||||
|
||||
static void callback(void *userp, const char *label, size_t label_len,
|
||||
const char *str, size_t len)
|
||||
{
|
||||
(void) userp;
|
||||
(void) label;
|
||||
(void) label_len;
|
||||
(void) str;
|
||||
(void) len;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
#ifdef __AFL_HAVE_MANUAL_CONTROL
|
||||
__AFL_INIT();
|
||||
#endif
|
||||
|
||||
unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF; // must be after __AFL_INIT
|
||||
// and before __AFL_LOOP!
|
||||
tinytemplate_instr_t program[1024];
|
||||
size_t max_instr = sizeof(program)/sizeof(program[0]);
|
||||
|
||||
while (__AFL_LOOP(10000)) {
|
||||
|
||||
int len = __AFL_FUZZ_TESTCASE_LEN; // don't use the macro directly in a
|
||||
// call!
|
||||
|
||||
tinytemplate_status_t status;
|
||||
|
||||
status = tinytemplate_compile((char*) buf, len, program, max_instr, NULL, NULL, 0);
|
||||
if (status == TINYTEMPLATE_STATUS_DONE)
|
||||
status = tinytemplate_eval((char*) buf, program, NULL, NULL, callback, NULL, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{{1+2}}
|
||||
@@ -0,0 +1,3 @@
|
||||
{% if 1 + 2 %}
|
||||
text
|
||||
{% end %}
|
||||
@@ -0,0 +1,5 @@
|
||||
{% if 1 + 2 %}
|
||||
text
|
||||
{% else %}
|
||||
hoyo
|
||||
{% end %}
|
||||
@@ -0,0 +1,3 @@
|
||||
{% for item in items %}
|
||||
{{item}}
|
||||
{% end %}
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
struct {
|
||||
const char *src;
|
||||
const char *exp;
|
||||
const char *params;
|
||||
} cases[] = {
|
||||
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SECTION_INPUT,
|
||||
SECTION_OUTPUT,
|
||||
SECTION_PARAMS,
|
||||
} Section;
|
||||
|
||||
static void runTest(const char *src, size_t len)
|
||||
{
|
||||
size_t params_offset;
|
||||
size_t params_length;
|
||||
size_t input_offset;
|
||||
size_t input_length;
|
||||
size_t output_offset;
|
||||
size_t output_length;
|
||||
|
||||
size_t i = 0;
|
||||
while (1) {
|
||||
while (i < len && src[i] != '@')
|
||||
i++;
|
||||
|
||||
if (i < len && isalpha(src[i])) {
|
||||
|
||||
size_t kword_off = i;
|
||||
do
|
||||
i++;
|
||||
while (i < len && isalpha(src[i]));
|
||||
size_t kword_len = i - kword_off;
|
||||
|
||||
bool is_kword = true;
|
||||
Section section;
|
||||
if (kword_len == 6 && !strncmp("params", src + kword_off, 6)) {
|
||||
section = SECTION_PARAMS;
|
||||
} else if (kword_len == 5 && !strncmp("input", src + kword_off, 5)) {
|
||||
section = SECTION_INPUT;
|
||||
} else if (kword_len == 6 && !strncmp("output", src + kword_off, 6)) {
|
||||
section = SECTION_OUTPUT;
|
||||
} else
|
||||
is_kword = false;
|
||||
|
||||
if (is_kword) {
|
||||
// Get to the end of the line
|
||||
while (i < len && (src[i] == ' ' || src[i] == '\t' || src[i] == '\r'))
|
||||
i++;
|
||||
if (i < len && src[i] != '\n') {
|
||||
|
||||
}
|
||||
while (i < len && src[i] != '\n')
|
||||
i++;
|
||||
if (i < len) {
|
||||
assert(src[i] == '\n');
|
||||
i++;
|
||||
}
|
||||
switch (section) {
|
||||
case SECTION_INPUT: input_offset = i; break;
|
||||
case SECTION_OUTPUT: output_offset = i; break;
|
||||
case SECTION_PARAMS: params_offset = i; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user