From 0fdebf904da0db7fe3c3690f02cf84f8a6f981b6 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Sat, 26 Mar 2016 10:37:59 +0100 Subject: [PATCH] Replace BUFSIZ with HCBUFSIZ and move them from stack to heap --- include/common.h | 9 +- include/shared.h | 4 +- src/oclHashcat.c | 112 +++++++++++++++--------- src/shared.c | 61 +++++++------ tools/rules_test/cpu_rules.c | 4 +- tools/rules_test/cpu_rules.h | 2 +- tools/rules_test/kernel2cpu_rule_test.c | 16 ++-- 7 files changed, 123 insertions(+), 85 deletions(-) diff --git a/include/common.h b/include/common.h index 1b784a342..079d7d57a 100644 --- a/include/common.h +++ b/include/common.h @@ -101,13 +101,12 @@ typedef uint64_t u64; typedef uint32_t uint; // we need to get rid of this sooner or later, for consistency -#define EXEC_CACHE 128 +#define EXEC_CACHE 128 -#define SPEED_CACHE 128 -#define SPEED_MAXAGE 4096 +#define SPEED_CACHE 128 +#define SPEED_MAXAGE 4096 -#undef BUFSIZ -#define BUFSIZ 8192 +#define HCBUFSIZ 0x10000 // general large space buffer size in case the size is unknown at compile-time /** * functions diff --git a/include/shared.h b/include/shared.h index 634e07fc1..0b24d77e2 100644 --- a/include/shared.h +++ b/include/shared.h @@ -1666,8 +1666,8 @@ int mangle_title (char arr[BLOCK_SIZE], int arr_len); int generate_random_rule (char rule_buf[RP_RULE_BUFSIZ], u32 rp_gen_func_min, u32 rp_gen_func_max); int _old_apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, char out[BLOCK_SIZE]); -int cpu_rule_to_kernel_rule (char rule_buf[BUFSIZ], uint rule_len, kernel_rule_t *rule); -int kernel_rule_to_cpu_rule (char rule_buf[BUFSIZ], kernel_rule_t *rule); +int cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule); +int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule); void *thread_device_watch (void *p); void *thread_keypress (void *p); diff --git a/src/oclHashcat.c b/src/oclHashcat.c index 37e1a2b0e..363abd194 100644 --- a/src/oclHashcat.c +++ b/src/oclHashcat.c @@ -3067,6 +3067,8 @@ static void autotune (hc_device_param_t *device_param) static void run_cracker (hc_device_param_t *device_param, const uint pws_cnt) { + char *line_buf = (char *) mymalloc (HCBUFSIZ); + // init speed timer uint speed_pos = device_param->speed_pos; @@ -3180,8 +3182,6 @@ static void run_cracker (hc_device_param_t *device_param, const uint pws_cnt) if (data.attack_mode == ATTACK_MODE_COMBI) { - char line_buf[BUFSIZ] = { 0 }; - uint i = 0; while (i < innerloop_left) @@ -3388,6 +3388,8 @@ static void run_cracker (hc_device_param_t *device_param, const uint pws_cnt) } device_param->speed_pos = speed_pos; + + myfree (line_buf); } static void load_segment (wl_data_t *wl_data, FILE *fd) @@ -4104,11 +4106,11 @@ static void *thread_outfile_remove (void *p) fseek (fp, out_info[j].seek, SEEK_SET); + char *line_buf = (char *) mymalloc (HCBUFSIZ); + while (!feof (fp)) { - char line_buf[BUFSIZ] = { 0 }; - - char *ptr = fgets (line_buf, BUFSIZ - 1, fp); + char *ptr = fgets (line_buf, HCBUFSIZ - 1, fp); if (ptr == NULL) break; @@ -4253,6 +4255,8 @@ static void *thread_outfile_remove (void *p) if (data.devices_status == STATUS_CRACKED) break; } + myfree (line_buf); + out_info[j].seek = ftell (fp); //hc_thread_mutex_unlock (mux_display); @@ -4362,6 +4366,8 @@ static void *thread_calc_stdin (void *p) autotune (device_param); + char *buf = (char *) mymalloc (HCBUFSIZ); + const uint attack_kern = data.attack_kern; const uint kernel_power = device_param->kernel_power; @@ -4381,9 +4387,7 @@ static void *thread_calc_stdin (void *p) while (words_cur < kernel_power) { - char buf[BUFSIZ] = { 0 }; - - char *line_buf = fgets (buf, sizeof (buf), stdin); + char *line_buf = fgets (buf, HCBUFSIZ - 1, stdin); if (line_buf == NULL) break; @@ -4494,6 +4498,8 @@ static void *thread_calc_stdin (void *p) device_param->kernel_accel = 0; device_param->kernel_loops = 0; + myfree (buf); + return NULL; } @@ -4874,7 +4880,7 @@ static void weak_hash_check (hc_device_param_t *device_param, const uint salt_po // hlfmt hashcat -static void hlfmt_hash_hashcat (char line_buf[BUFSIZ], int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_hashcat (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { if (data.username == 0) { @@ -4903,7 +4909,7 @@ static void hlfmt_hash_hashcat (char line_buf[BUFSIZ], int line_len, char **hash } } -static void hlfmt_user_hashcat (char line_buf[BUFSIZ], int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_hashcat (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { char *pos = NULL; int len = 0; @@ -4933,7 +4939,7 @@ static void hlfmt_user_hashcat (char line_buf[BUFSIZ], int line_len, char **user // hlfmt pwdump -static int hlfmt_detect_pwdump (char line_buf[BUFSIZ], int line_len) +static int hlfmt_detect_pwdump (char *line_buf, int line_len) { int sep_cnt = 0; @@ -4958,7 +4964,7 @@ static int hlfmt_detect_pwdump (char line_buf[BUFSIZ], int line_len) return 0; } -static void hlfmt_hash_pwdump (char line_buf[BUFSIZ], int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_pwdump (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { char *pos = NULL; int len = 0; @@ -4998,7 +5004,7 @@ static void hlfmt_hash_pwdump (char line_buf[BUFSIZ], int line_len, char **hashb *hashbuf_len = len; } -static void hlfmt_user_pwdump (char line_buf[BUFSIZ], int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_pwdump (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { char *pos = NULL; int len = 0; @@ -5028,7 +5034,7 @@ static void hlfmt_user_pwdump (char line_buf[BUFSIZ], int line_len, char **userb // hlfmt passwd -static int hlfmt_detect_passwd (char line_buf[BUFSIZ], int line_len) +static int hlfmt_detect_passwd (char *line_buf, int line_len) { int sep_cnt = 0; @@ -5053,7 +5059,7 @@ static int hlfmt_detect_passwd (char line_buf[BUFSIZ], int line_len) return 0; } -static void hlfmt_hash_passwd (char line_buf[BUFSIZ], int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_passwd (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { char *pos = NULL; int len = 0; @@ -5081,7 +5087,7 @@ static void hlfmt_hash_passwd (char line_buf[BUFSIZ], int line_len, char **hashb *hashbuf_len = len; } -static void hlfmt_user_passwd (char line_buf[BUFSIZ], int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_passwd (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { char *pos = NULL; int len = 0; @@ -5111,7 +5117,7 @@ static void hlfmt_user_passwd (char line_buf[BUFSIZ], int line_len, char **userb // hlfmt shadow -static int hlfmt_detect_shadow (char line_buf[BUFSIZ], int line_len) +static int hlfmt_detect_shadow (char *line_buf, int line_len) { int sep_cnt = 0; @@ -5125,19 +5131,19 @@ static int hlfmt_detect_shadow (char line_buf[BUFSIZ], int line_len) return 0; } -static void hlfmt_hash_shadow (char line_buf[BUFSIZ], int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_shadow (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { hlfmt_hash_passwd (line_buf, line_len, hashbuf_pos, hashbuf_len); } -static void hlfmt_user_shadow (char line_buf[BUFSIZ], int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_shadow (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { hlfmt_user_passwd (line_buf, line_len, userbuf_pos, userbuf_len); } // hlfmt main -static void hlfmt_hash (uint hashfile_format, char line_buf[BUFSIZ], int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash (uint hashfile_format, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { switch (hashfile_format) { @@ -5148,7 +5154,7 @@ static void hlfmt_hash (uint hashfile_format, char line_buf[BUFSIZ], int line_le } } -static void hlfmt_user (uint hashfile_format, char line_buf[BUFSIZ], int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user (uint hashfile_format, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { switch (hashfile_format) { @@ -5189,10 +5195,10 @@ static uint hlfmt_detect (FILE *fp, uint max_check) uint num_check = 0; + char *line_buf = (char *) mymalloc (HCBUFSIZ); + while (!feof (fp)) { - char line_buf[BUFSIZ] = { 0 }; - int line_len = fgetl (fp, line_buf); if (line_len == 0) continue; @@ -5206,6 +5212,8 @@ static uint hlfmt_detect (FILE *fp, uint max_check) num_check++; } + myfree (line_buf); + uint hashlist_format = HLFMT_HASHCAT; for (int i = 1; i < HLFMTS_CNT; i++) @@ -10527,12 +10535,12 @@ int main (int argc, char **argv) uint line_num = 0; + char *line_buf = (char *) mymalloc (HCBUFSIZ); + while (!feof (pot_fp)) { line_num++; - char line_buf[BUFSIZ] = { 0 }; - int line_len = fgetl (pot_fp, line_buf); if (line_len == 0) continue; @@ -10642,6 +10650,8 @@ int main (int argc, char **argv) pot_cnt++; } + myfree (line_buf); + fclose (pot_fp); SUPPRESS_OUTPUT = 0; @@ -11166,12 +11176,12 @@ int main (int argc, char **argv) uint line_num = 0; + char *line_buf = (char *) mymalloc (HCBUFSIZ); + while (!feof (fp)) { line_num++; - char line_buf[BUFSIZ] = { 0 }; - int line_len = fgetl (fp, line_buf); if (line_len == 0) continue; @@ -11309,6 +11319,8 @@ int main (int argc, char **argv) } } + myfree (line_buf); + fclose (fp); if (data.quiet == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_avail, hashes_avail, 100.00); @@ -11824,11 +11836,17 @@ int main (int argc, char **argv) if (fp != NULL) { + char *line_buf = (char *) mymalloc (HCBUFSIZ); + + // to be safe work with a copy (because of line_len loop, i etc) + // moved up here because it's easier to handle continue case + // it's just 64kb + + char *line_buf_cpy = (char *) mymalloc (HCBUFSIZ); + while (!feof (fp)) { - char line_buf[BUFSIZ] = { 0 }; - - char *ptr = fgets (line_buf, BUFSIZ - 1, fp); + char *ptr = fgets (line_buf, HCBUFSIZ - 1, fp); if (ptr == NULL) break; @@ -11868,10 +11886,6 @@ int main (int argc, char **argv) // here we have in line_buf: ESSID:MAC1:MAC2 (without the plain) // manipulate salt_buf - // to be safe work with a copy (because of line_len loop, i etc) - - char line_buf_cpy[BUFSIZ] = { 0 }; - memcpy (line_buf_cpy, line_buf, i); char *mac2_pos = strrchr (line_buf_cpy, ':'); @@ -11974,6 +11988,10 @@ int main (int argc, char **argv) } } + myfree (line_buf_cpy); + + myfree (line_buf); + fclose (fp); } } @@ -12349,7 +12367,7 @@ int main (int argc, char **argv) all_kernel_rules_buf = (kernel_rule_t **) mycalloc (rp_files_cnt, sizeof (kernel_rule_t *)); } - char rule_buf[BUFSIZ] = { 0 }; + char *rule_buf = (char *) mymalloc (HCBUFSIZ); int rule_len = 0; @@ -12379,7 +12397,7 @@ int main (int argc, char **argv) while (!feof (fp)) { - memset (rule_buf, 0, BUFSIZ); + memset (rule_buf, 0, HCBUFSIZ); rule_len = fgetl (fp, rule_buf); @@ -12507,7 +12525,7 @@ int main (int argc, char **argv) kernel_rules_avail += INCR_RULES; } - memset (rule_buf, 0, BLOCK_SIZE); + memset (rule_buf, 0, HCBUFSIZ); rule_len = (int) generate_random_rule (rule_buf, rp_gen_func_min, rp_gen_func_max); @@ -12518,6 +12536,8 @@ int main (int argc, char **argv) } } + myfree (rule_buf); + /** * generate NOP rules */ @@ -15095,11 +15115,11 @@ int main (int argc, char **argv) return (-1); } - char line_buf[BUFSIZ] = { 0 }; + char *line_buf = (char *) mymalloc (HCBUFSIZ); while (!feof (mask_fp)) { - memset (line_buf, 0, BUFSIZ); + memset (line_buf, 0, HCBUFSIZ); int line_len = fgetl (mask_fp, line_buf); @@ -15119,6 +15139,8 @@ int main (int argc, char **argv) maskcnt++; } + myfree (line_buf); + fclose (mask_fp); } else @@ -15234,13 +15256,13 @@ int main (int argc, char **argv) return (-1); } - char line_buf[BUFSIZ] = { 0 }; + char *line_buf = (char *) mymalloc (HCBUFSIZ); uint masks_avail = 1; while (!feof (mask_fp)) { - memset (line_buf, 0, BUFSIZ); + memset (line_buf, 0, HCBUFSIZ); int line_len = fgetl (mask_fp, line_buf); @@ -15260,6 +15282,8 @@ int main (int argc, char **argv) maskcnt++; } + myfree (line_buf); + fclose (mask_fp); mask_from_file = 1; @@ -15411,13 +15435,13 @@ int main (int argc, char **argv) return (-1); } - char line_buf[BUFSIZ] = { 0 }; + char *line_buf = (char *) mymalloc (HCBUFSIZ); uint masks_avail = 1; while (!feof (mask_fp)) { - memset (line_buf, 0, BUFSIZ); + memset (line_buf, 0, HCBUFSIZ); int line_len = fgetl (mask_fp, line_buf); @@ -15437,6 +15461,8 @@ int main (int argc, char **argv) maskcnt++; } + myfree (line_buf); + fclose (mask_fp); mask_from_file = 1; diff --git a/src/shared.c b/src/shared.c index f1002b7a9..aeb914f91 100644 --- a/src/shared.c +++ b/src/shared.c @@ -4197,13 +4197,13 @@ uint count_lines (FILE *fd) { uint cnt = 0; - char *buf = (char *) mymalloc (BUFSIZ + 1); + char *buf = (char *) mymalloc (HCBUFSIZ + 1); char prev = '\n'; while (!feof (fd)) { - size_t nread = fread (buf, sizeof (char), BUFSIZ, fd); + size_t nread = fread (buf, sizeof (char), HCBUFSIZ, fd); if (nread < 1) continue; @@ -5453,7 +5453,7 @@ int fgetl (FILE *fp, char *line_buf) line_len++; - if (line_len == BUFSIZ) line_len--; + if (line_len == HCBUFSIZ) line_len--; if (c == '\n') break; } @@ -8856,18 +8856,18 @@ restore_data_t *init_restore (int argc, char **argv) if (rd->pid) { - char pidbin[BUFSIZ] = { 0 }; + char *pidbin = (char *) mymalloc (HCBUFSIZ); int pidbin_len = -1; #ifdef _POSIX - snprintf (pidbin, sizeof (pidbin) - 1, "/proc/%d/cmdline", rd->pid); + snprintf (pidbin, HCBUFSIZ - 1, "/proc/%d/cmdline", rd->pid); FILE *fd = fopen (pidbin, "rb"); if (fd) { - pidbin_len = fread (pidbin, 1, BUFSIZ, fd); + pidbin_len = fread (pidbin, 1, HCBUFSIZ, fd); pidbin[pidbin_len] = 0; @@ -8892,12 +8892,12 @@ restore_data_t *init_restore (int argc, char **argv) #elif _WIN HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, rd->pid); - char pidbin2[BUFSIZ] = { 0 }; + char *pidbin2 = (char *) mymalloc (HCBUFSIZ); int pidbin2_len = -1; - pidbin_len = GetModuleFileName (NULL, pidbin, BUFSIZ); - pidbin2_len = GetModuleFileNameEx (hProcess, NULL, pidbin2, BUFSIZ); + pidbin_len = GetModuleFileName (NULL, pidbin, HCBUFSIZ); + pidbin2_len = GetModuleFileNameEx (hProcess, NULL, pidbin2, HCBUFSIZ); pidbin[pidbin_len] = 0; pidbin2[pidbin2_len] = 0; @@ -8911,7 +8911,12 @@ restore_data_t *init_restore (int argc, char **argv) exit (-1); } } + + myfree (pidbin2); + #endif + + myfree (pidbin); } if (rd->version_bin < RESTORE_MIN) @@ -8966,11 +8971,11 @@ void read_restore (const char *eff_restore_file, restore_data_t *rd) rd->argv = (char **) mycalloc (rd->argc, sizeof (char *)); + char *buf = (char *) mymalloc (HCBUFSIZ); + for (uint i = 0; i < rd->argc; i++) { - char buf[BUFSIZ] = { 0 }; - - if (fgets (buf, BUFSIZ - 1, fp) == NULL) + if (fgets (buf, HCBUFSIZ - 1, fp) == NULL) { log_error ("ERROR: cannot read %s", eff_restore_file); @@ -8984,6 +8989,8 @@ void read_restore (const char *eff_restore_file, restore_data_t *rd) rd->argv[i] = mystrdup (buf); } + myfree (buf); + fclose (fp); char new_cwd[1024] = { 0 }; @@ -9180,11 +9187,11 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file) int line_num = 0; + char *buf = (char *) mymalloc (HCBUFSIZ); + while (!feof (fp)) { - char buf[BUFSIZ]; - - char *line_buf = fgets (buf, sizeof (buf) - 1, fp); + char *line_buf = fgets (buf, HCBUFSIZ - 1, fp); if (line_buf == NULL) break; @@ -9313,6 +9320,8 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file) } } + myfree (buf); + fclose (fp); // todo: print loaded 'cnt' message @@ -11540,11 +11549,11 @@ int sha1axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) if ((input_len < DISPLAY_LEN_MIN_13300) || (input_len > DISPLAY_LEN_MAX_13300)) return (PARSER_GLOBAL_LENGTH); if (memcmp (SIGNATURE_AXCRYPT_SHA1, input_buf, 13)) return (PARSER_SIGNATURE_UNMATCHED); - + u32 *digest = (u32 *) hash_buf->digest; input_buf +=14; - + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); @@ -18943,22 +18952,22 @@ int axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) char *salt_pos; char *wrapped_key_pos; - + char *data_pos; salt->salt_iter = atoi (wrapping_rounds_pos); - + salt_pos = strchr (wrapping_rounds_pos, '*'); if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - + uint wrapping_rounds_len = salt_pos - wrapping_rounds_pos; /* Skip '*' */ salt_pos++; - + data_pos = salt_pos; - + wrapped_key_pos = strchr (salt_pos, '*'); if (wrapped_key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); @@ -18983,7 +18992,7 @@ int axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) salt->salt_buf[4] = hex_to_u32 ((const u8 *) &data_pos[ 0]); salt->salt_buf[5] = hex_to_u32 ((const u8 *) &data_pos[ 8]); - salt->salt_buf[6] = hex_to_u32 ((const u8 *) &data_pos[16]); + salt->salt_buf[6] = hex_to_u32 ((const u8 *) &data_pos[16]); salt->salt_buf[7] = hex_to_u32 ((const u8 *) &data_pos[24]); salt->salt_buf[8] = hex_to_u32 ((const u8 *) &data_pos[32]); salt->salt_buf[9] = hex_to_u32 ((const u8 *) &data_pos[40]); @@ -19574,7 +19583,7 @@ int conv_itoc (const u8 c) #define GET_P0_CONV(rule) INCR_POS; rule_buf[rule_pos] = conv_itoc (((rule)->cmds[rule_cnt] >> 8) & 0xff) #define GET_P1_CONV(rule) INCR_POS; rule_buf[rule_pos] = conv_itoc (((rule)->cmds[rule_cnt] >> 16) & 0xff) -int cpu_rule_to_kernel_rule (char rule_buf[BUFSIZ], uint rule_len, kernel_rule_t *rule) +int cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule) { uint rule_pos; uint rule_cnt; @@ -19790,11 +19799,11 @@ int cpu_rule_to_kernel_rule (char rule_buf[BUFSIZ], uint rule_len, kernel_rule_t return (0); } -int kernel_rule_to_cpu_rule (char rule_buf[BUFSIZ], kernel_rule_t *rule) +int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule) { uint rule_cnt; uint rule_pos; - uint rule_len = BUFSIZ - 1; // maximum possible len + uint rule_len = HCBUFSIZ - 1; // maximum possible len char rule_cmd; diff --git a/tools/rules_test/cpu_rules.c b/tools/rules_test/cpu_rules.c index 1acc91286..98cc77bd3 100644 --- a/tools/rules_test/cpu_rules.c +++ b/tools/rules_test/cpu_rules.c @@ -486,7 +486,7 @@ int mangle_title (char arr[BLOCK_SIZE], int arr_len) return (arr_len); } -int generate_random_rule (char rule_buf[RP_RULE_BUFSIZ], u32 rp_gen_func_min, u32 rp_gen_func_max) +int generate_random_rule (char *rule_buf, u32 rp_gen_func_min, u32 rp_gen_func_max) { u32 rp_gen_num = get_random_num (rp_gen_func_min, rp_gen_func_max); @@ -929,7 +929,7 @@ int apply_rule_cpu (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, c return (out_len); } -int cpu_rule_to_kernel_rule (char rule_buf[BUFSIZ], uint rule_len, kernel_rule_t *rule) +int cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule) { uint rule_pos; uint rule_cnt; diff --git a/tools/rules_test/cpu_rules.h b/tools/rules_test/cpu_rules.h index 44bbc1e65..fcb36fae7 100644 --- a/tools/rules_test/cpu_rules.h +++ b/tools/rules_test/cpu_rules.h @@ -53,7 +53,7 @@ int mangle_chr_decr (u8 arr[BLOCK_SIZE], int arr_len, int upos); int mangle_title (char arr[BLOCK_SIZE], int arr_len); int generate_random_rule (char rule_buf[RP_RULE_BUFSIZ], u32 rp_gen_func_min, u32 rp_gen_func_max); int apply_rule_cpu (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, char out[BLOCK_SIZE]); -int cpu_rule_to_kernel_rule (char rule_buf[BUFSIZ], uint rule_len, kernel_rule_t *rule); +int cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule); bool class_num (char c); bool class_lower (char c); diff --git a/tools/rules_test/kernel2cpu_rule_test.c b/tools/rules_test/kernel2cpu_rule_test.c index a9dcb0d56..acc1a0ec4 100644 --- a/tools/rules_test/kernel2cpu_rule_test.c +++ b/tools/rules_test/kernel2cpu_rule_test.c @@ -11,7 +11,7 @@ #define RP_GEN_FUNC_MAX 4 #define PW_MAX 32 #define LINE_SIG_LEN RP_GEN_FUNC_MAX * 2 + 1 - +3 int max_len = 0; #include "cpu_rules.h" @@ -59,7 +59,9 @@ int main (int argc, char **argv) { FILE *fp = stdin; - char rule_buf[BUFSIZ]; + char *rule_buf = (char *) malloc (HCBUFSIZ); + + char *line_buf = (char *) mymalloc (HCBUFSIZ); int rp_gen_func_min = RP_GEN_FUNC_MIN; int rp_gen_func_max = RP_GEN_FUNC_MAX; @@ -72,9 +74,7 @@ int main (int argc, char **argv) if (feof (fp)) break; - char line_buf[BUFSIZ + 1]; - - char *line_ptr = fgets (line_buf, BUFSIZ, fp); + char *line_ptr = fgets (line_buf, HCBUFSIZ - 1, fp); if (line_ptr == NULL) continue; @@ -116,7 +116,7 @@ int main (int argc, char **argv) } else { - strncpy (rule_buf, argv[1], BUFSIZ); + strncpy (rule_buf, argv[1], HCBUFSIZ - 1); rule_len = strlen (rule_buf); } @@ -204,5 +204,9 @@ int main (int argc, char **argv) fclose (fp); + free (line_buf); + + free (rule_buf); + return 0; }