From 8e5c5d27661b3436bad23f194a2d43cdd8d3d826 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 29 Aug 2022 20:27:39 +0200 Subject: [PATCH] Fix: Some minor bugs lol --- Implementierung/lib/md2_impls/md2_common.h | 5 ++--- Implementierung/src/helper.c | 4 ++-- Implementierung/src/io.c | 4 ++-- Implementierung/src/md2_impls/md2_2.c | 4 ++++ Implementierung/src/md2_impls/md2_3.c | 4 ++-- Implementierung/src/md2_impls/md2_common.c | 5 ++++- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Implementierung/lib/md2_impls/md2_common.h b/Implementierung/lib/md2_impls/md2_common.h index 80a014f..ca139e8 100644 --- a/Implementierung/lib/md2_impls/md2_common.h +++ b/Implementierung/lib/md2_impls/md2_common.h @@ -72,8 +72,7 @@ void md2_checksum(size_t len, uint8_t* buf); * @brief Calculates checksum of buf and writes it into a target * * @param len Length of data which the checksum should be calculated of - * @param buf Location of the data. Make sure to reserve 16 bytes more so the - * chechsum fits! + * @param buf Location of the data. * @param checksum the output checksum */ void md2_checksum_with_target(size_t len, const uint8_t* buf, @@ -100,7 +99,7 @@ void md2_process_detailed_benchmark_step(enum md2_detailed_benchmark_step step); * @brief Print the detailed benchmark result * */ -void md2_print_detailed_benchmark_result(); +void md2_print_detailed_benchmark_result(void); /** * @brief Add padding and allocate extra space for the checksum diff --git a/Implementierung/src/helper.c b/Implementierung/src/helper.c index d6101a5..9c8711a 100644 --- a/Implementierung/src/helper.c +++ b/Implementierung/src/helper.c @@ -57,7 +57,7 @@ enum argumentParseResult parseArguments(int argc, char **argv, static struct option longOptions[] = { {"version", required_argument, NULL, 'V'}, {"benchmark", optional_argument, NULL, 'B'}, - {"test", optional_argument, NULL, 'T'}, + {"test", no_argument, NULL, 'T'}, {"help", no_argument, NULL, 'h'}, {NULL}}; int longOptionIndex = 0; @@ -101,7 +101,7 @@ enum argumentParseResult parseArguments(int argc, char **argv, if (argc > optind) { c->filename = argv[optind]; } else if (!c->runTests) { - fprintf(stderr, "%s: missing poisional argument -- 'file'\n", argv[0]); + fprintf(stderr, "%s: missing positional argument -- 'file'\n", argv[0]); return RESULT_EXIT_FAILURE; } diff --git a/Implementierung/src/io.c b/Implementierung/src/io.c index 3ee2ada..0371265 100644 --- a/Implementierung/src/io.c +++ b/Implementierung/src/io.c @@ -65,9 +65,9 @@ uint8_t* read_file(const char* path, size_t* size) { return NULL; } - size_t bytes_read = fread(data, 1, statOfFile.st_size, f); + fread(data, 1, statOfFile.st_size, f); - if (bytes_read == 0 || ferror(f)) { + if (ferror(f)) { fclose(f); if (errno == 0) errno = EIO; return NULL; diff --git a/Implementierung/src/md2_impls/md2_2.c b/Implementierung/src/md2_impls/md2_2.c index c359da5..259080c 100644 --- a/Implementierung/src/md2_impls/md2_2.c +++ b/Implementierung/src/md2_impls/md2_2.c @@ -51,6 +51,10 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) { size_t size = fread(data, 1, bytes_left_to_process, file); if (size == 0 || ferror(file) || feof(file)) { if (errno == 0) errno = EIO; + fclose(file); + free(data); + free(messageDigestBuf); + free(checksum); return; } diff --git a/Implementierung/src/md2_impls/md2_3.c b/Implementierung/src/md2_impls/md2_3.c index 160c2fe..223562b 100644 --- a/Implementierung/src/md2_impls/md2_3.c +++ b/Implementierung/src/md2_impls/md2_3.c @@ -20,7 +20,7 @@ void* process_hash(void* threadArgs) { uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t)); if (messageDigestBuf == NULL) { - return NULL; + pthread_exit(NULL); } process_nothread_hash(args->len, args->buf, messageDigestBuf); @@ -32,7 +32,7 @@ void* process_checksum(void* threasdArgs) { uint8_t* checksum = calloc(16, sizeof(uint8_t)); if (checksum == NULL) { - return NULL; + pthread_exit(NULL); } md2_checksum_with_target(args->len, args->buf, checksum); diff --git a/Implementierung/src/md2_impls/md2_common.c b/Implementierung/src/md2_impls/md2_common.c index 04dcf0e..c2144ec 100644 --- a/Implementierung/src/md2_impls/md2_common.c +++ b/Implementierung/src/md2_impls/md2_common.c @@ -108,12 +108,15 @@ void md2_second_loop(uint8_t* messageDigestBuf) { u_int8_t t = 0; SECOND_LOOP_START_MARK - for (int j = 0; j < 18; j++) { + for (int j = 0; j < 17; j++) { for (int k = 0; k < 48; k++) { t = messageDigestBuf[k] = messageDigestBuf[k] ^ MD2_PI_SUBST[t]; } t = (t + j) & 255; } + for (int k = 0; k < 16; k++) { + t = messageDigestBuf[k] = messageDigestBuf[k] ^ MD2_PI_SUBST[t]; + } SECOND_LOOP_END_MARK }