/*-1* Copyright (c) 2024 Kyle Evans <[email protected]>2*3* SPDX-License-Identifier: BSD-2-Clause4*/56#include <sys/param.h>7#include <sys/socket.h>89#include <assert.h>10#include <signal.h>11#include <stdbool.h>12#include <stdio.h>13#include <stdlib.h>14#include <unistd.h>1516#include <libder.h>1718#include "fuzzers.h"1920int21LLVMFuzzerTestOneInput(const uint8_t *data, size_t sz)22{23struct libder_ctx *ctx;24struct libder_object *obj;25size_t readsz;26int ret;27bool strict;2829if (sz < 2)30return (-1);3132/*33* I worked this in originally by just using the high bit of the first34* byte, but then I realized that encoding it that way would make it35* impossible to get strict validation of universal and application36* tags. The former is a bit more important than the latter.37*/38strict = !!data[0];39data++;40sz--;4142ctx = libder_open();43libder_set_strict(ctx, strict);44ret = -1;45readsz = sz;46obj = libder_read(ctx, data, &readsz);47if (obj == NULL || readsz != sz)48goto out;4950if (obj != NULL) {51uint8_t *buf = NULL;52size_t bufsz = 0;5354/*55* If we successfully read it, then it shouldn't56* overflow. We're letting libder allocate the buffer,57* so we shouldn't be able to hit the 'too small' bit.58*59* I can't imagine what other errors might happen, so60* we'll just assert on it.61*/62buf = libder_write(ctx, obj, buf, &bufsz);63if (buf == NULL)64goto out;6566assert(bufsz != 0);6768free(buf);69}7071ret = 0;7273out:74libder_obj_free(obj);75libder_close(ctx);7677return (ret);78}798081