"Fossies" - the Fresh Open Source Software Archive

Member "tor-0.4.1.6/src/test/fuzz/fuzz_diff_apply.c" (10 Jun 2019, 1327 Bytes) of package /linux/misc/tor-0.4.1.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "fuzz_diff_apply.c": 0.3.5.8_vs_0.4.0.5.

    1 /* Copyright (c) 2016-2019, The Tor Project, Inc. */
    2 /* See LICENSE for licensing information */
    3 
    4 #define CONSDIFF_PRIVATE
    5 
    6 #include "orconfig.h"
    7 #include "core/or/or.h"
    8 #include "feature/dircommon/consdiff.h"
    9 
   10 #include "test/fuzz/fuzzing.h"
   11 
   12 static int
   13 mock_consensus_compute_digest_(const char *c, size_t len,
   14                                consensus_digest_t *d)
   15 {
   16   (void)c;
   17   (void)len;
   18   memset(d->sha3_256, 3, sizeof(d->sha3_256));
   19   return 0;
   20 }
   21 
   22 static int
   23 mock_consensus_digest_eq_(const uint8_t *a, const uint8_t *b)
   24 {
   25   (void)a;
   26   (void)b;
   27   return 1;
   28 }
   29 
   30 int
   31 fuzz_init(void)
   32 {
   33   MOCK(consensus_compute_digest, mock_consensus_compute_digest_);
   34   MOCK(consensus_digest_eq, mock_consensus_digest_eq_);
   35   return 0;
   36 }
   37 
   38 int
   39 fuzz_cleanup(void)
   40 {
   41   UNMOCK(consensus_compute_digest);
   42   UNMOCK(consensus_digest_eq);
   43   return 0;
   44 }
   45 
   46 int
   47 fuzz_main(const uint8_t *stdin_buf, size_t data_size)
   48 {
   49 #define SEP "=====\n"
   50 #define SEPLEN strlen(SEP)
   51   const uint8_t *separator = tor_memmem(stdin_buf, data_size, SEP, SEPLEN);
   52   if (! separator)
   53     return 0;
   54   size_t c1_len = separator - stdin_buf;
   55   const char *c1 = (const char *)stdin_buf;
   56   size_t c2_len = data_size - c1_len - SEPLEN;
   57   const char *c2 = (const char *)separator + SEPLEN;
   58 
   59   char *c3 = consensus_diff_apply(c1, c1_len, c2, c2_len);
   60 
   61   tor_free(c3);
   62 
   63   return 0;
   64 }