etc.git


etc

~ scripts and random things
git clone https://github.com/djnnvx/etc.git
log | files | refs | archive

fuzz_lws_mock.h (2048B)

      1 #pragma once
      2 #include <stddef.h>
      3 #include <stdint.h>
      4 #include <string.h>
      5 
      6 /* Fuzzer-controlled header values.  Set these before calling any ttyd
      7  * function that reads HTTP headers; the mock lws_hdr_* functions return
      8  * whatever is stored here.                                                 */
      9 extern char _fuzz_auth_header[4096];
     10 extern int  _fuzz_auth_header_len;
     11 extern char _fuzz_custom_header[4096];
     12 extern int  _fuzz_custom_header_len;
     13 
     14 /* Additional header mocks for websocket/protocol fuzzing */
     15 extern char _fuzz_uri_path[4096];
     16 extern int  _fuzz_uri_path_len;
     17 extern char _fuzz_origin[4096];
     18 extern int  _fuzz_origin_len;
     19 extern char _fuzz_host[4096];
     20 extern int  _fuzz_host_len;
     21 
     22 /* URI arg fragments for lws_hdr_copy_fragment(WSI_TOKEN_HTTP_URI_ARGS) */
     23 #define FUZZ_MAX_URI_ARGS 8
     24 extern char _fuzz_uri_args[FUZZ_MAX_URI_ARGS][256];
     25 extern int  _fuzz_uri_args_len[FUZZ_MAX_URI_ARGS];
     26 extern int  _fuzz_uri_args_count;
     27 
     28 /* Reset all mock state — call at the start of every fuzz iteration. */
     29 void fuzz_lws_reset(void);
     30 
     31 /* Convenience setters. */
     32 static inline void fuzz_lws_set_auth(const char *v, int len) {
     33     int n = len < 4095 ? len : 4095;
     34     memcpy(_fuzz_auth_header, v, n);
     35     _fuzz_auth_header[n] = '\0';
     36     _fuzz_auth_header_len = n;
     37 }
     38 static inline void fuzz_lws_set_custom(const char *v, int len) {
     39     int n = len < 4095 ? len : 4095;
     40     memcpy(_fuzz_custom_header, v, n);
     41     _fuzz_custom_header[n] = '\0';
     42     _fuzz_custom_header_len = n;
     43 }
     44 static inline void fuzz_lws_set_uri_path(const char *v, int len) {
     45     int n = len < 4095 ? len : 4095;
     46     memcpy(_fuzz_uri_path, v, n);
     47     _fuzz_uri_path[n] = '\0';
     48     _fuzz_uri_path_len = n;
     49 }
     50 static inline void fuzz_lws_set_origin(const char *v, int len) {
     51     int n = len < 4095 ? len : 4095;
     52     memcpy(_fuzz_origin, v, n);
     53     _fuzz_origin[n] = '\0';
     54     _fuzz_origin_len = n;
     55 }
     56 static inline void fuzz_lws_set_host(const char *v, int len) {
     57     int n = len < 4095 ? len : 4095;
     58     memcpy(_fuzz_host, v, n);
     59     _fuzz_host[n] = '\0';
     60     _fuzz_host_len = n;
     61 }