Commit 0f7d1503 authored by Tomáš Stefan's avatar Tomáš Stefan

fn param checks, new test file

parent 5d1eada7
......@@ -4,7 +4,7 @@
#include "types.h"
xref_t *xref_init();
xref_t *xref_init(void);
void xref_free(xref_t *xref);
......
......@@ -113,6 +113,9 @@ sigil_err_t pdf_peek_char(sigil_t *sgl, char *result)
{
sigil_err_t err;
if (sgl == NULL || result == NULL)
return ERR_PARAMETER;
err = pdf_get_char(sgl, result);
if (err != ERR_NO)
return err;
......@@ -392,6 +395,9 @@ sigil_err_t parse_number(sigil_t *sgl, size_t *number)
char c;
int digits = 0;
if (sgl == NULL || number == NULL)
return ERR_PARAMETER;
*number = 0;
err = skip_leading_whitespaces(sgl);
......@@ -469,7 +475,7 @@ sigil_err_t parse_indirect_reference(sigil_t *sgl, reference_t *ref)
return ERR_NO;
}
// parse the key of the couple key - value in the dictionary
// parse the key of the pair key - value in the dictionary
sigil_err_t parse_dict_key(sigil_t *sgl, dict_key_t *dict_key)
{
sigil_err_t err;
......@@ -477,6 +483,9 @@ sigil_err_t parse_dict_key(sigil_t *sgl, dict_key_t *dict_key)
char tmp[DICT_KEY_MAX],
c;
if (sgl == NULL || dict_key == NULL)
return ERR_PARAMETER;
sigil_zeroize(tmp, DICT_KEY_MAX * sizeof(*tmp));
if (parse_word(sgl, ">>") == ERR_NO)
......@@ -599,7 +608,7 @@ sigil_err_t reference_to_offset(sigil_t *sgl, const reference_t *ref, size_t *re
{
xref_entry_t *xref_entry;
if (sgl == NULL || ref == NULL || sgl->xref == NULL)
if (sgl == NULL || ref == NULL || sgl->xref == NULL || result == NULL)
return ERR_PARAMETER;
if (sgl->xref->capacity <= ref->object_num)
......@@ -651,7 +660,7 @@ const char *sigil_err_string(sigil_err_t err)
void print_module_name(const char *module_name, int verbosity)
{
if (verbosity < 1)
if (verbosity < 1 || module_name == NULL)
return;
printf("\n + Testing module: %s\n", module_name);
......@@ -671,7 +680,7 @@ void print_module_result(int result, int verbosity)
void print_test_item(const char *test_name, int verbosity)
{
if (verbosity < 2)
if (verbosity < 2 || test_name == NULL)
return;
printf(" - %-32s", test_name);
......@@ -693,6 +702,9 @@ sigil_t *test_prepare_sgl_content(char *content, size_t size)
{
sigil_t *sgl;
if (content == NULL)
return NULL;
if (sigil_init(&sgl) != ERR_NO)
return NULL;
......@@ -708,6 +720,9 @@ sigil_t *test_prepare_sgl_path(const char *path)
{
sigil_t *sgl;
if (path == NULL)
return NULL;
if (sigil_init(&sgl) != ERR_NO)
return NULL;
......
......@@ -237,6 +237,9 @@ sigil_err_t load_digest(sigil_t *sgl)
const X509_ALGOR *tmp_alg = NULL;
const ASN1_OCTET_STRING *tmp_hash = NULL;
if (sgl == NULL || sgl->contents == NULL || sgl->certificates)
return ERR_PARAMETER;
contents = sgl->contents->contents_hex;
contents_len = strlen(contents);
......@@ -387,6 +390,9 @@ sigil_err_t compare_digest(sigil_t *sgl)
sgl->hash_cmp_result = HASH_CMP_RESULT_DIFFER;
if (sgl->md_hash == NULL || sgl->computed_digest == NULL)
return ERR_PARAMETER;
if (ASN1_STRING_cmp(sgl->md_hash, sgl->computed_digest) == 0)
sgl->hash_cmp_result = HASH_CMP_RESULT_MATCH;
......@@ -397,11 +403,11 @@ sigil_err_t verify_digest(sigil_t *sgl, int *result)
{
sigil_err_t err;
*result = 1;
if (sgl == NULL)
if (sgl == NULL || *result == NULL)
return ERR_PARAMETER;
*result = 1;
err = compute_digest_pkcs1(sgl);
if (err != ERR_NO)
return err;
......
......@@ -18,6 +18,9 @@ static sigil_err_t parse_subfilter(sigil_t *sgl)
char tmp[SUBFILTER_MAX],
c;
if (sgl == NULL)
return ERR_PARAMETER;
sigil_zeroize(tmp, SUBFILTER_MAX * sizeof(*tmp));
err = parse_word(sgl, "/");
......@@ -58,6 +61,9 @@ static sigil_err_t parse_byte_range(sigil_t *sgl)
size_t start,
length;
if (sgl == NULL)
return ERR_PARAMETER;
err = parse_word(sgl, "[");
if (err != ERR_NO)
return err;
......
......@@ -10,6 +10,9 @@ sigil_err_t find_sig_field(sigil_t *sgl)
dict_key_t dict_key;
int other_ft;
if (sgl == NULL)
return ERR_PARAMETER;
err = ERR_NO_DATA;
for (size_t i = 0; i < sgl->fields.capacity; i++) {
......
......@@ -2,8 +2,6 @@
#include <stdlib.h>
#include <string.h>
#include <types.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include "acroform.h"
#include "auxiliary.h"
#include "catalog_dict.h"
......@@ -18,8 +16,6 @@
#include "types.h"
#include "xref.h"
#include <openssl/err.h>
sigil_err_t sigil_init(sigil_t **sgl)
{
// function parameter checks
......@@ -139,11 +135,12 @@ sigil_err_t sigil_set_pdf_file(sigil_t *sgl, FILE *pdf_file)
sigil_err_t sigil_set_pdf_path(sigil_t *sgl, const char *path_to_pdf)
{
if (sgl == NULL || path_to_pdf == NULL)
return ERR_PARAMETER;
FILE *pdf_file = NULL;
if (sgl == NULL || path_to_pdf == NULL) {
return ERR_PARAMETER;
}
#ifdef _WIN32
// convert path to wchar_t
size_t out_size;
......@@ -473,7 +470,7 @@ int sigil_sigil_self_test(int verbosity)
print_test_item("VERIFY x509.rsa_sha1", verbosity);
{
sgl = test_prepare_sgl_path("test/EduLib__adbe.x509.rsa_sha1.pdf");
sgl = test_prepare_sgl_path("test/subtype_adbe.x509.rsa_sha1.pdf");
if (sgl == NULL)
goto failed;
......
......@@ -13,6 +13,9 @@ static sigil_err_t determine_xref_type(sigil_t *sgl)
sigil_err_t err;
char c;
if (sgl == NULL)
return ERR_PARAMETER;
if ((err = pdf_peek_char(sgl, &c)) != ERR_NO)
return err;
......@@ -76,7 +79,7 @@ static void free_xref_entry(xref_entry_t *entry)
}
}
xref_t *xref_init()
xref_t *xref_init(void)
{
xref_t *xref = malloc(sizeof(xref_t));
if (xref == NULL)
......@@ -153,6 +156,9 @@ sigil_err_t read_xref_table(sigil_t *sgl)
int xref_end = 0;
sigil_err_t err;
if (sgl == NULL)
return ERR_PARAMETER;
if (sgl->xref == NULL) {
sgl->xref = xref_init();
if (sgl->xref == NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment