|
| 1 | +/* |
| 2 | + Fuzzing parse_lpq_entry |
| 3 | + Copyright (C) Douglas Bagnall <[email protected]> 2021 |
| 4 | +
|
| 5 | + This program is free software; you can redistribute it and/or modify |
| 6 | + it under the terms of the GNU General Public License as published by |
| 7 | + the Free Software Foundation; either version 3 of the License, or |
| 8 | + (at your option) any later version. |
| 9 | +
|
| 10 | + This program is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + GNU General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU General Public License |
| 16 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +*/ |
| 18 | +#include "../../source3/include/includes.h" |
| 19 | +#include "printing.h" |
| 20 | +#include "fuzzing/fuzzing.h" |
| 21 | + |
| 22 | + |
| 23 | +int LLVMFuzzerInitialize(int *argc, char ***argv) |
| 24 | +{ |
| 25 | + return 0; |
| 26 | +} |
| 27 | + |
| 28 | +#define MAX_LENGTH (1024 * 1024) |
| 29 | +char line[MAX_LENGTH + 1]; |
| 30 | + |
| 31 | +int LLVMFuzzerTestOneInput(uint8_t *input, size_t len) |
| 32 | +{ |
| 33 | + enum printing_types printing_type; |
| 34 | + print_queue_struct pq_buf = {0}; |
| 35 | + print_status_struct status = {0}; |
| 36 | + bool first; |
| 37 | + unsigned x; |
| 38 | + TALLOC_CTX *frame = NULL; |
| 39 | + |
| 40 | + if (len < 1 || len > MAX_LENGTH) { |
| 41 | + return 0; |
| 42 | + } |
| 43 | + |
| 44 | + x = input[0]; |
| 45 | + input++; |
| 46 | + len--; |
| 47 | + |
| 48 | + /* There are 14 types, default goes to bsd */ |
| 49 | + printing_type = x & 15; |
| 50 | + first = (x & 16) ? true : false; |
| 51 | + |
| 52 | + memcpy(line, input, len); |
| 53 | + line[len] = '\0'; |
| 54 | + |
| 55 | + /* parse_lpq_bsd requires a stackframe */ |
| 56 | + frame = talloc_stackframe(); |
| 57 | + |
| 58 | + parse_lpq_entry(printing_type, |
| 59 | + line, |
| 60 | + &pq_buf, /* out */ |
| 61 | + &status, /* out */ |
| 62 | + first); |
| 63 | + talloc_free(frame); |
| 64 | + return 0; |
| 65 | +} |
0 commit comments