Loading...
Searching...
No Matches
ada_c.c
Go to the documentation of this file.
#include "ada_c.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size == 0) return 0;
size_t half = size / 2;
const char* input = (const char*)data;
size_t input_len = half;
const char* base = (const char*)(data + half);
size_t base_len = size - half;
ada_url out = ada_parse(input, input_len);
bool is_valid = ada_is_valid(out);
if (is_valid) {
ada_set_href(out, input, input_len);
ada_set_host(out, input, input_len);
ada_set_hostname(out, input, input_len);
ada_set_protocol(out, input, input_len);
ada_set_username(out, input, input_len);
ada_set_password(out, input, input_len);
ada_set_port(out, input, input_len);
ada_set_pathname(out, input, input_len);
ada_set_search(out, input, input_len);
ada_set_hash(out, input, input_len);
ada_get_hash(out);
ada_get_host(out);
ada_get_host_type(out);
ada_get_hostname(out);
ada_get_href(out);
ada_owned_string out_get_origin = ada_get_origin(out);
ada_get_pathname(out);
ada_get_username(out);
ada_get_password(out);
ada_get_protocol(out);
ada_get_port(out);
ada_get_search(out);
ada_get_scheme_type(out);
ada_has_credentials(out);
ada_has_empty_hostname(out);
ada_has_hostname(out);
ada_has_non_empty_username(out);
ada_has_non_empty_password(out);
ada_has_port(out);
ada_has_password(out);
ada_has_hash(out);
ada_has_search(out);
ada_get_components(out);
ada_clear_port(out);
ada_clear_hash(out);
ada_clear_search(out);
ada_free_owned_string(out_get_origin);
/* Test ada_copy */
ada_url out_copy = ada_copy(out);
bool copy_is_valid = ada_is_valid(out_copy);
if (copy_is_valid) {
ada_string href_orig = ada_get_href(out);
ada_string href_copy = ada_get_href(out_copy);
/* The copy should have the same href (after our setters above) */
(void)href_orig;
(void)href_copy;
}
ada_free(out_copy);
}
bool can_parse_result = ada_can_parse(input, input_len);
(void)can_parse_result;
ada_free(out);
ada_url out_with_base = ada_parse_with_base(input, input_len, base, base_len);
bool with_base_valid = ada_is_valid(out_with_base);
if (with_base_valid) {
ada_string href = ada_get_href(out_with_base);
volatile size_t len = href.length;
(void)len;
ada_owned_string origin = ada_get_origin(out_with_base);
ada_free_owned_string(origin);
ada_get_hostname(out_with_base);
ada_get_pathname(out_with_base);
ada_get_search(out_with_base);
ada_get_hash(out_with_base);
ada_get_protocol(out_with_base);
ada_get_port(out_with_base);
ada_get_username(out_with_base);
ada_get_password(out_with_base);
ada_has_credentials(out_with_base);
ada_has_port(out_with_base);
ada_has_hash(out_with_base);
ada_has_search(out_with_base);
ada_get_components(out_with_base);
}
bool can_parse_with_base =
ada_can_parse_with_base(input, input_len, base, base_len);
/* Consistency check: can_parse_with_base should match
* ada_is_valid(ada_parse_with_base(...)) */
if (can_parse_with_base != with_base_valid) {
printf("ada_can_parse_with_base inconsistency: can_parse=%d is_valid=%d\n",
can_parse_with_base, with_base_valid);
abort();
}
ada_free(out_with_base);
{
ada_owned_string unicode_result = ada_idna_to_unicode(input, input_len);
volatile size_t ulen = unicode_result.length;
(void)ulen;
ada_free_owned_string(unicode_result);
ada_owned_string ascii_result = ada_idna_to_ascii(input, input_len);
volatile size_t alen = ascii_result.length;
(void)alen;
ada_free_owned_string(ascii_result);
}
{
const char* version = ada_get_version();
volatile size_t vlen = strlen(version);
(void)vlen;
ada_version_components ver_comps = ada_get_version_components();
volatile int major = ver_comps.major;
(void)major;
}
{
ada_url_search_params sp = ada_parse_search_params(input, input_len);
/* Size */
volatile size_t sp_size = ada_search_params_size(sp);
(void)sp_size;
/* Append */
ada_search_params_append(sp, input, input_len, base, base_len);
/* Set (replaces first match) */
ada_search_params_set(sp, input, input_len, base, base_len);
/* has */
volatile bool has_key = ada_search_params_has(sp, input, input_len);
(void)has_key;
/* has_value */
volatile bool has_kv =
ada_search_params_has_value(sp, input, input_len, base, base_len);
(void)has_kv;
/* get - returns ada_string (may have data=NULL if not found) */
ada_string got = ada_search_params_get(sp, input, input_len);
volatile size_t got_len = got.length;
(void)got_len;
/* get_all */
ada_strings all_vals = ada_search_params_get_all(sp, input, input_len);
volatile size_t all_size = ada_strings_size(all_vals);
for (size_t i = 0; i < all_size; i++) {
ada_string s = ada_strings_get(all_vals, i);
volatile size_t slen = s.length;
(void)slen;
}
ada_free_strings(all_vals);
/* sort */
ada_search_params_sort(sp);
/* to_string */
ada_owned_string sp_str = ada_search_params_to_string(sp);
volatile size_t str_len = sp_str.length;
(void)str_len;
ada_free_owned_string(sp_str);
/* keys iterator */
ada_url_search_params_keys_iter keys_iter = ada_search_params_get_keys(sp);
while (ada_search_params_keys_iter_has_next(keys_iter)) {
ada_string k = ada_search_params_keys_iter_next(keys_iter);
volatile size_t klen = k.length;
(void)klen;
}
ada_free_search_params_keys_iter(keys_iter);
/* values iterator */
ada_url_search_params_values_iter values_iter =
ada_search_params_get_values(sp);
while (ada_search_params_values_iter_has_next(values_iter)) {
ada_string v = ada_search_params_values_iter_next(values_iter);
volatile size_t vlen = v.length;
(void)vlen;
}
ada_free_search_params_values_iter(values_iter);
/* entries iterator */
ada_url_search_params_entries_iter entries_iter =
ada_search_params_get_entries(sp);
while (ada_search_params_entries_iter_has_next(entries_iter)) {
ada_string_pair entry = ada_search_params_entries_iter_next(entries_iter);
volatile size_t ek = entry.key.length;
volatile size_t ev = entry.value.length;
(void)ek;
(void)ev;
}
ada_free_search_params_entries_iter(entries_iter);
/* remove */
ada_search_params_remove(sp, input, input_len);
/* remove_value */
ada_search_params_remove_value(sp, input, input_len, base, base_len);
/* reset */
ada_search_params_reset(sp, base, base_len);
/* Verify size after reset */
volatile size_t sp_size_after = ada_search_params_size(sp);
(void)sp_size_after;
ada_free_search_params(sp);
}
return 0;
}
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition ada_c.c:8
ada_c.h
Includes the C definitions for Ada. This is a C file, not C++.
ada_parse_search_params
ada_url_search_params ada_parse_search_params(const char *input, size_t length)
Definition ada_c.cpp:469
ada_get_hash
ada_string ada_get_hash(ada_url result)
Definition ada_c.cpp:169
ada_set_port
bool ada_set_port(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:291
ada_search_params_get_all
ada_strings ada_search_params_get_all(ada_url_search_params result, const char *key, size_t key_length)
Definition ada_c.cpp:596
ada_clear_search
void ada_clear_search(ada_url result)
Definition ada_c.cpp:362
ada_free_search_params_entries_iter
void ada_free_search_params_entries_iter(ada_url_search_params_entries_iter result)
Definition ada_c.cpp:718
ada_set_host
bool ada_set_host(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:247
ada_has_password
bool ada_has_password(ada_url result)
Definition ada_c.cpp:417
ada_search_params_keys_iter_has_next
bool ada_search_params_keys_iter_has_next(ada_url_search_params_keys_iter result)
Definition ada_c.cpp:681
ada_search_params_values_iter_next
ada_string ada_search_params_values_iter_next(ada_url_search_params_values_iter result)
Definition ada_c.cpp:696
ada_free_search_params_keys_iter
void ada_free_search_params_keys_iter(ada_url_search_params_keys_iter result)
Definition ada_c.cpp:663
ada_get_pathname
ada_string ada_get_pathname(ada_url result)
Definition ada_c.cpp:196
ada_get_components
const ada_url_components * ada_get_components(ada_url result)
Definition ada_c.cpp:442
ada_search_params_has_value
bool ada_search_params_has_value(ada_url_search_params result, const char *key, size_t key_length, const char *value, size_t value_length)
Definition ada_c.cpp:570
ada_has_empty_hostname
bool ada_has_empty_hostname(ada_url result)
Definition ada_c.cpp:377
ada_free_strings
void ada_free_strings(ada_strings result)
Definition ada_c.cpp:641
ada_search_params_append
void ada_search_params_append(ada_url_search_params result, const char *key, size_t key_length, const char *value, size_t value_length)
Definition ada_c.cpp:518
ada_has_non_empty_password
bool ada_has_non_empty_password(ada_url result)
Definition ada_c.cpp:401
ada_set_password
bool ada_set_password(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:282
ada_search_params_get_entries
ada_url_search_params_entries_iter ada_search_params_get_entries(ada_url_search_params result)
Definition ada_c.cpp:630
ada_url_search_params_entries_iter
void * ada_url_search_params_entries_iter
Definition ada_c.h:125
ada_get_hostname
ada_string ada_get_hostname(ada_url result)
Definition ada_c.cpp:187
ada_can_parse_with_base
bool ada_can_parse_with_base(const char *input, size_t input_length, const char *base, size_t base_length)
Definition ada_c.cpp:92
ada_search_params_get
ada_string ada_search_params_get(ada_url_search_params result, const char *key, size_t key_length)
Definition ada_c.cpp:582
ada_get_host_type
uint8_t ada_get_host_type(ada_url result)
Definition ada_c.cpp:223
ada_get_password
ada_string ada_get_password(ada_url result)
Definition ada_c.cpp:151
ada_get_version
const char * ada_get_version()
Definition ada_c.cpp:752
ada_get_version_components
ada_version_components ada_get_version_components()
Definition ada_c.cpp:754
ada_strings
void * ada_strings
Definition ada_c.h:116
ada_search_params_sort
void ada_search_params_sort(ada_url_search_params result)
Definition ada_c.cpp:501
ada_idna_to_unicode
ada_owned_string ada_idna_to_unicode(const char *input, size_t length)
Definition ada_c.cpp:451
ada_search_params_remove_value
void ada_search_params_remove_value(ada_url_search_params result, const char *key, size_t key_length, const char *value, size_t value_length)
Definition ada_c.cpp:549
ada_set_hostname
bool ada_set_hostname(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:255
ada_parse_with_base
ada_url ada_parse_with_base(const char *input, size_t input_length, const char *base, size_t base_length)
Definition ada_c.cpp:75
ada_free_search_params
void ada_free_search_params(ada_url_search_params result)
Definition ada_c.cpp:475
ada_get_port
ada_string ada_get_port(ada_url result)
Definition ada_c.cpp:160
ada_set_pathname
bool ada_set_pathname(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:299
ada_get_host
ada_string ada_get_host(ada_url result)
Definition ada_c.cpp:178
ada_url_search_params
void * ada_url_search_params
Definition ada_c.h:113
ada_parse
ada_url ada_parse(const char *input, size_t length)
Definition ada_c.cpp:70
ada_has_port
bool ada_has_port(ada_url result)
Definition ada_c.cpp:409
ada_clear_hash
void ada_clear_hash(ada_url result)
Definition ada_c.cpp:349
ada_free_owned_string
void ada_free_owned_string(ada_owned_string owned)
Definition ada_c.cpp:129
ada_search_params_to_string
ada_owned_string ada_search_params_to_string(ada_url_search_params result)
Definition ada_c.cpp:480
ada_strings_get
ada_string ada_strings_get(ada_strings result, size_t index)
Definition ada_c.cpp:654
ada_set_href
bool ada_set_href(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:239
ada_free
void ada_free(ada_url result)
Definition ada_c.cpp:98
ada_url
void * ada_url
Definition ada_c.h:39
ada_search_params_entries_iter_has_next
bool ada_search_params_entries_iter_has_next(ada_url_search_params_entries_iter result)
Definition ada_c.cpp:737
ada_search_params_size
size_t ada_search_params_size(ada_url_search_params result)
Definition ada_c.cpp:492
ada_get_origin
ada_owned_string ada_get_origin(ada_url result)
Definition ada_c.cpp:114
ada_get_protocol
ada_string ada_get_protocol(ada_url result)
Definition ada_c.cpp:214
ada_free_search_params_values_iter
void ada_free_search_params_values_iter(ada_url_search_params_values_iter result)
Definition ada_c.cpp:690
ada_set_username
bool ada_set_username(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:273
ada_get_username
ada_string ada_get_username(ada_url result)
Definition ada_c.cpp:142
ada_get_scheme_type
uint8_t ada_get_scheme_type(ada_url result)
Definition ada_c.cpp:231
ada_search_params_keys_iter_next
ada_string ada_search_params_keys_iter_next(ada_url_search_params_keys_iter result)
Definition ada_c.cpp:668
ada_search_params_entries_iter_next
ada_string_pair ada_search_params_entries_iter_next(ada_url_search_params_entries_iter result)
Definition ada_c.cpp:724
ada_clear_port
void ada_clear_port(ada_url result)
Definition ada_c.cpp:336
ada_is_valid
bool ada_is_valid(ada_url result)
Definition ada_c.cpp:108
ada_search_params_get_keys
ada_url_search_params_keys_iter ada_search_params_get_keys(ada_url_search_params result)
Definition ada_c.cpp:608
ada_idna_to_ascii
ada_owned_string ada_idna_to_ascii(const char *input, size_t length)
Definition ada_c.cpp:460
ada_set_search
void ada_set_search(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:315
ada_url_search_params_keys_iter
void * ada_url_search_params_keys_iter
Definition ada_c.h:117
ada_search_params_values_iter_has_next
bool ada_search_params_values_iter_has_next(ada_url_search_params_values_iter result)
Definition ada_c.cpp:709
ada_search_params_set
void ada_search_params_set(ada_url_search_params result, const char *key, size_t key_length, const char *value, size_t value_length)
Definition ada_c.cpp:529
ada_get_href
ada_string ada_get_href(ada_url result)
Definition ada_c.cpp:133
ada_set_protocol
bool ada_set_protocol(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:264
ada_strings_size
size_t ada_strings_size(ada_strings result)
Definition ada_c.cpp:646
ada_search_params_get_values
ada_url_search_params_values_iter ada_search_params_get_values(ada_url_search_params result)
Definition ada_c.cpp:619
ada_has_hash
bool ada_has_hash(ada_url result)
Definition ada_c.cpp:425
ada_search_params_has
bool ada_search_params_has(ada_url_search_params result, const char *key, size_t key_length)
Definition ada_c.cpp:560
ada_has_hostname
bool ada_has_hostname(ada_url result)
Definition ada_c.cpp:385
ada_has_credentials
bool ada_has_credentials(ada_url result)
Definition ada_c.cpp:369
ada_url_search_params_values_iter
void * ada_url_search_params_values_iter
Definition ada_c.h:118
ada_can_parse
bool ada_can_parse(const char *input, size_t length)
Definition ada_c.cpp:88
ada_get_search
ada_string ada_get_search(ada_url result)
Definition ada_c.cpp:205
ada_search_params_reset
void ada_search_params_reset(ada_url_search_params result, const char *input, size_t length)
Definition ada_c.cpp:509
ada_search_params_remove
void ada_search_params_remove(ada_url_search_params result, const char *key, size_t key_length)
Definition ada_c.cpp:540
ada_has_non_empty_username
bool ada_has_non_empty_username(ada_url result)
Definition ada_c.cpp:393
ada_has_search
bool ada_has_search(ada_url result)
Definition ada_c.cpp:433
ada_copy
ada_url ada_copy(ada_url input)
Definition ada_c.cpp:103
ada_set_hash
void ada_set_hash(ada_url result, const char *input, size_t length)
Definition ada_c.cpp:329
ada_owned_string
Definition ada_c.h:23
ada_owned_string::length
size_t length
Definition ada_c.h:25
ada_string_pair
Definition ada_c.h:120
ada_string_pair::value
ada_string value
Definition ada_c.h:122
ada_string_pair::key
ada_string key
Definition ada_c.h:121
ada_string
Definition ada_c.h:17
ada_string::length
size_t length
Definition ada_c.h:19
ada_version_components
Definition ada_c.h:188
ada_version_components::major
int major
Definition ada_c.h:189