1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Replace BUFSIZ with HCBUFSIZ and move them from stack to heap

This commit is contained in:
Jens Steube 2016-03-26 10:37:59 +01:00
parent 3f694cf960
commit 0fdebf904d
7 changed files with 123 additions and 85 deletions

View File

@ -101,13 +101,12 @@ typedef uint64_t u64;
typedef uint32_t uint; // we need to get rid of this sooner or later, for consistency 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_CACHE 128
#define SPEED_MAXAGE 4096 #define SPEED_MAXAGE 4096
#undef BUFSIZ #define HCBUFSIZ 0x10000 // general large space buffer size in case the size is unknown at compile-time
#define BUFSIZ 8192
/** /**
* functions * functions

View File

@ -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 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 _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 cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule);
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);
void *thread_device_watch (void *p); void *thread_device_watch (void *p);
void *thread_keypress (void *p); void *thread_keypress (void *p);

View File

@ -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) static void run_cracker (hc_device_param_t *device_param, const uint pws_cnt)
{ {
char *line_buf = (char *) mymalloc (HCBUFSIZ);
// init speed timer // init speed timer
uint speed_pos = device_param->speed_pos; 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) if (data.attack_mode == ATTACK_MODE_COMBI)
{ {
char line_buf[BUFSIZ] = { 0 };
uint i = 0; uint i = 0;
while (i < innerloop_left) 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; device_param->speed_pos = speed_pos;
myfree (line_buf);
} }
static void load_segment (wl_data_t *wl_data, FILE *fd) 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); fseek (fp, out_info[j].seek, SEEK_SET);
char *line_buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (fp)) while (!feof (fp))
{ {
char line_buf[BUFSIZ] = { 0 }; char *ptr = fgets (line_buf, HCBUFSIZ - 1, fp);
char *ptr = fgets (line_buf, BUFSIZ - 1, fp);
if (ptr == NULL) break; if (ptr == NULL) break;
@ -4253,6 +4255,8 @@ static void *thread_outfile_remove (void *p)
if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_CRACKED) break;
} }
myfree (line_buf);
out_info[j].seek = ftell (fp); out_info[j].seek = ftell (fp);
//hc_thread_mutex_unlock (mux_display); //hc_thread_mutex_unlock (mux_display);
@ -4362,6 +4366,8 @@ static void *thread_calc_stdin (void *p)
autotune (device_param); autotune (device_param);
char *buf = (char *) mymalloc (HCBUFSIZ);
const uint attack_kern = data.attack_kern; const uint attack_kern = data.attack_kern;
const uint kernel_power = device_param->kernel_power; const uint kernel_power = device_param->kernel_power;
@ -4381,9 +4387,7 @@ static void *thread_calc_stdin (void *p)
while (words_cur < kernel_power) while (words_cur < kernel_power)
{ {
char buf[BUFSIZ] = { 0 }; char *line_buf = fgets (buf, HCBUFSIZ - 1, stdin);
char *line_buf = fgets (buf, sizeof (buf), stdin);
if (line_buf == NULL) break; if (line_buf == NULL) break;
@ -4494,6 +4498,8 @@ static void *thread_calc_stdin (void *p)
device_param->kernel_accel = 0; device_param->kernel_accel = 0;
device_param->kernel_loops = 0; device_param->kernel_loops = 0;
myfree (buf);
return NULL; return NULL;
} }
@ -4874,7 +4880,7 @@ static void weak_hash_check (hc_device_param_t *device_param, const uint salt_po
// hlfmt hashcat // 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) 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; char *pos = NULL;
int len = 0; int len = 0;
@ -4933,7 +4939,7 @@ static void hlfmt_user_hashcat (char line_buf[BUFSIZ], int line_len, char **user
// hlfmt pwdump // 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; int sep_cnt = 0;
@ -4958,7 +4964,7 @@ static int hlfmt_detect_pwdump (char line_buf[BUFSIZ], int line_len)
return 0; 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; char *pos = NULL;
int len = 0; int len = 0;
@ -4998,7 +5004,7 @@ static void hlfmt_hash_pwdump (char line_buf[BUFSIZ], int line_len, char **hashb
*hashbuf_len = len; *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; char *pos = NULL;
int len = 0; int len = 0;
@ -5028,7 +5034,7 @@ static void hlfmt_user_pwdump (char line_buf[BUFSIZ], int line_len, char **userb
// hlfmt passwd // 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; int sep_cnt = 0;
@ -5053,7 +5059,7 @@ static int hlfmt_detect_passwd (char line_buf[BUFSIZ], int line_len)
return 0; 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; char *pos = NULL;
int len = 0; int len = 0;
@ -5081,7 +5087,7 @@ static void hlfmt_hash_passwd (char line_buf[BUFSIZ], int line_len, char **hashb
*hashbuf_len = len; *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; char *pos = NULL;
int len = 0; int len = 0;
@ -5111,7 +5117,7 @@ static void hlfmt_user_passwd (char line_buf[BUFSIZ], int line_len, char **userb
// hlfmt shadow // 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; int sep_cnt = 0;
@ -5125,19 +5131,19 @@ static int hlfmt_detect_shadow (char line_buf[BUFSIZ], int line_len)
return 0; 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); 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_user_passwd (line_buf, line_len, userbuf_pos, userbuf_len);
} }
// hlfmt main // 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) 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) switch (hashfile_format)
{ {
@ -5189,10 +5195,10 @@ static uint hlfmt_detect (FILE *fp, uint max_check)
uint num_check = 0; uint num_check = 0;
char *line_buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (fp)) while (!feof (fp))
{ {
char line_buf[BUFSIZ] = { 0 };
int line_len = fgetl (fp, line_buf); int line_len = fgetl (fp, line_buf);
if (line_len == 0) continue; if (line_len == 0) continue;
@ -5206,6 +5212,8 @@ static uint hlfmt_detect (FILE *fp, uint max_check)
num_check++; num_check++;
} }
myfree (line_buf);
uint hashlist_format = HLFMT_HASHCAT; uint hashlist_format = HLFMT_HASHCAT;
for (int i = 1; i < HLFMTS_CNT; i++) for (int i = 1; i < HLFMTS_CNT; i++)
@ -10527,12 +10535,12 @@ int main (int argc, char **argv)
uint line_num = 0; uint line_num = 0;
char *line_buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (pot_fp)) while (!feof (pot_fp))
{ {
line_num++; line_num++;
char line_buf[BUFSIZ] = { 0 };
int line_len = fgetl (pot_fp, line_buf); int line_len = fgetl (pot_fp, line_buf);
if (line_len == 0) continue; if (line_len == 0) continue;
@ -10642,6 +10650,8 @@ int main (int argc, char **argv)
pot_cnt++; pot_cnt++;
} }
myfree (line_buf);
fclose (pot_fp); fclose (pot_fp);
SUPPRESS_OUTPUT = 0; SUPPRESS_OUTPUT = 0;
@ -11166,12 +11176,12 @@ int main (int argc, char **argv)
uint line_num = 0; uint line_num = 0;
char *line_buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (fp)) while (!feof (fp))
{ {
line_num++; line_num++;
char line_buf[BUFSIZ] = { 0 };
int line_len = fgetl (fp, line_buf); int line_len = fgetl (fp, line_buf);
if (line_len == 0) continue; if (line_len == 0) continue;
@ -11309,6 +11319,8 @@ int main (int argc, char **argv)
} }
} }
myfree (line_buf);
fclose (fp); fclose (fp);
if (data.quiet == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_avail, hashes_avail, 100.00); 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) 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)) while (!feof (fp))
{ {
char line_buf[BUFSIZ] = { 0 }; char *ptr = fgets (line_buf, HCBUFSIZ - 1, fp);
char *ptr = fgets (line_buf, BUFSIZ - 1, fp);
if (ptr == NULL) break; 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) // here we have in line_buf: ESSID:MAC1:MAC2 (without the plain)
// manipulate salt_buf // 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); memcpy (line_buf_cpy, line_buf, i);
char *mac2_pos = strrchr (line_buf_cpy, ':'); 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); 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 *)); 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; int rule_len = 0;
@ -12379,7 +12397,7 @@ int main (int argc, char **argv)
while (!feof (fp)) while (!feof (fp))
{ {
memset (rule_buf, 0, BUFSIZ); memset (rule_buf, 0, HCBUFSIZ);
rule_len = fgetl (fp, rule_buf); rule_len = fgetl (fp, rule_buf);
@ -12507,7 +12525,7 @@ int main (int argc, char **argv)
kernel_rules_avail += INCR_RULES; 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); 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 * generate NOP rules
*/ */
@ -15095,11 +15115,11 @@ int main (int argc, char **argv)
return (-1); return (-1);
} }
char line_buf[BUFSIZ] = { 0 }; char *line_buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (mask_fp)) while (!feof (mask_fp))
{ {
memset (line_buf, 0, BUFSIZ); memset (line_buf, 0, HCBUFSIZ);
int line_len = fgetl (mask_fp, line_buf); int line_len = fgetl (mask_fp, line_buf);
@ -15119,6 +15139,8 @@ int main (int argc, char **argv)
maskcnt++; maskcnt++;
} }
myfree (line_buf);
fclose (mask_fp); fclose (mask_fp);
} }
else else
@ -15234,13 +15256,13 @@ int main (int argc, char **argv)
return (-1); return (-1);
} }
char line_buf[BUFSIZ] = { 0 }; char *line_buf = (char *) mymalloc (HCBUFSIZ);
uint masks_avail = 1; uint masks_avail = 1;
while (!feof (mask_fp)) while (!feof (mask_fp))
{ {
memset (line_buf, 0, BUFSIZ); memset (line_buf, 0, HCBUFSIZ);
int line_len = fgetl (mask_fp, line_buf); int line_len = fgetl (mask_fp, line_buf);
@ -15260,6 +15282,8 @@ int main (int argc, char **argv)
maskcnt++; maskcnt++;
} }
myfree (line_buf);
fclose (mask_fp); fclose (mask_fp);
mask_from_file = 1; mask_from_file = 1;
@ -15411,13 +15435,13 @@ int main (int argc, char **argv)
return (-1); return (-1);
} }
char line_buf[BUFSIZ] = { 0 }; char *line_buf = (char *) mymalloc (HCBUFSIZ);
uint masks_avail = 1; uint masks_avail = 1;
while (!feof (mask_fp)) while (!feof (mask_fp))
{ {
memset (line_buf, 0, BUFSIZ); memset (line_buf, 0, HCBUFSIZ);
int line_len = fgetl (mask_fp, line_buf); int line_len = fgetl (mask_fp, line_buf);
@ -15437,6 +15461,8 @@ int main (int argc, char **argv)
maskcnt++; maskcnt++;
} }
myfree (line_buf);
fclose (mask_fp); fclose (mask_fp);
mask_from_file = 1; mask_from_file = 1;

View File

@ -4197,13 +4197,13 @@ uint count_lines (FILE *fd)
{ {
uint cnt = 0; uint cnt = 0;
char *buf = (char *) mymalloc (BUFSIZ + 1); char *buf = (char *) mymalloc (HCBUFSIZ + 1);
char prev = '\n'; char prev = '\n';
while (!feof (fd)) 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; if (nread < 1) continue;
@ -5453,7 +5453,7 @@ int fgetl (FILE *fp, char *line_buf)
line_len++; line_len++;
if (line_len == BUFSIZ) line_len--; if (line_len == HCBUFSIZ) line_len--;
if (c == '\n') break; if (c == '\n') break;
} }
@ -8856,18 +8856,18 @@ restore_data_t *init_restore (int argc, char **argv)
if (rd->pid) if (rd->pid)
{ {
char pidbin[BUFSIZ] = { 0 }; char *pidbin = (char *) mymalloc (HCBUFSIZ);
int pidbin_len = -1; int pidbin_len = -1;
#ifdef _POSIX #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"); FILE *fd = fopen (pidbin, "rb");
if (fd) if (fd)
{ {
pidbin_len = fread (pidbin, 1, BUFSIZ, fd); pidbin_len = fread (pidbin, 1, HCBUFSIZ, fd);
pidbin[pidbin_len] = 0; pidbin[pidbin_len] = 0;
@ -8892,12 +8892,12 @@ restore_data_t *init_restore (int argc, char **argv)
#elif _WIN #elif _WIN
HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, rd->pid); HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, rd->pid);
char pidbin2[BUFSIZ] = { 0 }; char *pidbin2 = (char *) mymalloc (HCBUFSIZ);
int pidbin2_len = -1; int pidbin2_len = -1;
pidbin_len = GetModuleFileName (NULL, pidbin, BUFSIZ); pidbin_len = GetModuleFileName (NULL, pidbin, HCBUFSIZ);
pidbin2_len = GetModuleFileNameEx (hProcess, NULL, pidbin2, BUFSIZ); pidbin2_len = GetModuleFileNameEx (hProcess, NULL, pidbin2, HCBUFSIZ);
pidbin[pidbin_len] = 0; pidbin[pidbin_len] = 0;
pidbin2[pidbin2_len] = 0; pidbin2[pidbin2_len] = 0;
@ -8911,7 +8911,12 @@ restore_data_t *init_restore (int argc, char **argv)
exit (-1); exit (-1);
} }
} }
myfree (pidbin2);
#endif #endif
myfree (pidbin);
} }
if (rd->version_bin < RESTORE_MIN) 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 *)); rd->argv = (char **) mycalloc (rd->argc, sizeof (char *));
char *buf = (char *) mymalloc (HCBUFSIZ);
for (uint i = 0; i < rd->argc; i++) for (uint i = 0; i < rd->argc; i++)
{ {
char buf[BUFSIZ] = { 0 }; if (fgets (buf, HCBUFSIZ - 1, fp) == NULL)
if (fgets (buf, BUFSIZ - 1, fp) == NULL)
{ {
log_error ("ERROR: cannot read %s", eff_restore_file); 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); rd->argv[i] = mystrdup (buf);
} }
myfree (buf);
fclose (fp); fclose (fp);
char new_cwd[1024] = { 0 }; char new_cwd[1024] = { 0 };
@ -9180,11 +9187,11 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file)
int line_num = 0; int line_num = 0;
char *buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (fp)) while (!feof (fp))
{ {
char buf[BUFSIZ]; char *line_buf = fgets (buf, HCBUFSIZ - 1, fp);
char *line_buf = fgets (buf, sizeof (buf) - 1, fp);
if (line_buf == NULL) break; if (line_buf == NULL) break;
@ -9313,6 +9320,8 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file)
} }
} }
myfree (buf);
fclose (fp); fclose (fp);
// todo: print loaded 'cnt' message // 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 ((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); if (memcmp (SIGNATURE_AXCRYPT_SHA1, input_buf, 13)) return (PARSER_SIGNATURE_UNMATCHED);
u32 *digest = (u32 *) hash_buf->digest; u32 *digest = (u32 *) hash_buf->digest;
input_buf +=14; input_buf +=14;
digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]);
digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]);
digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); 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 *salt_pos;
char *wrapped_key_pos; char *wrapped_key_pos;
char *data_pos; char *data_pos;
salt->salt_iter = atoi (wrapping_rounds_pos); salt->salt_iter = atoi (wrapping_rounds_pos);
salt_pos = strchr (wrapping_rounds_pos, '*'); salt_pos = strchr (wrapping_rounds_pos, '*');
if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED);
uint wrapping_rounds_len = salt_pos - wrapping_rounds_pos; uint wrapping_rounds_len = salt_pos - wrapping_rounds_pos;
/* Skip '*' */ /* Skip '*' */
salt_pos++; salt_pos++;
data_pos = salt_pos; data_pos = salt_pos;
wrapped_key_pos = strchr (salt_pos, '*'); wrapped_key_pos = strchr (salt_pos, '*');
if (wrapped_key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); 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[4] = hex_to_u32 ((const u8 *) &data_pos[ 0]);
salt->salt_buf[5] = hex_to_u32 ((const u8 *) &data_pos[ 8]); 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[7] = hex_to_u32 ((const u8 *) &data_pos[24]);
salt->salt_buf[8] = hex_to_u32 ((const u8 *) &data_pos[32]); salt->salt_buf[8] = hex_to_u32 ((const u8 *) &data_pos[32]);
salt->salt_buf[9] = hex_to_u32 ((const u8 *) &data_pos[40]); 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_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) #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_pos;
uint rule_cnt; 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); 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_cnt;
uint rule_pos; uint rule_pos;
uint rule_len = BUFSIZ - 1; // maximum possible len uint rule_len = HCBUFSIZ - 1; // maximum possible len
char rule_cmd; char rule_cmd;

View File

@ -486,7 +486,7 @@ int mangle_title (char arr[BLOCK_SIZE], int arr_len)
return (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); 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); 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_pos;
uint rule_cnt; uint rule_cnt;

View File

@ -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 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 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 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_num (char c);
bool class_lower (char c); bool class_lower (char c);

View File

@ -11,7 +11,7 @@
#define RP_GEN_FUNC_MAX 4 #define RP_GEN_FUNC_MAX 4
#define PW_MAX 32 #define PW_MAX 32
#define LINE_SIG_LEN RP_GEN_FUNC_MAX * 2 + 1 #define LINE_SIG_LEN RP_GEN_FUNC_MAX * 2 + 1
3
int max_len = 0; int max_len = 0;
#include "cpu_rules.h" #include "cpu_rules.h"
@ -59,7 +59,9 @@ int main (int argc, char **argv)
{ {
FILE *fp = stdin; 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_min = RP_GEN_FUNC_MIN;
int rp_gen_func_max = RP_GEN_FUNC_MAX; int rp_gen_func_max = RP_GEN_FUNC_MAX;
@ -72,9 +74,7 @@ int main (int argc, char **argv)
if (feof (fp)) break; if (feof (fp)) break;
char line_buf[BUFSIZ + 1]; char *line_ptr = fgets (line_buf, HCBUFSIZ - 1, fp);
char *line_ptr = fgets (line_buf, BUFSIZ, fp);
if (line_ptr == NULL) continue; if (line_ptr == NULL) continue;
@ -116,7 +116,7 @@ int main (int argc, char **argv)
} }
else else
{ {
strncpy (rule_buf, argv[1], BUFSIZ); strncpy (rule_buf, argv[1], HCBUFSIZ - 1);
rule_len = strlen (rule_buf); rule_len = strlen (rule_buf);
} }
@ -204,5 +204,9 @@ int main (int argc, char **argv)
fclose (fp); fclose (fp);
free (line_buf);
free (rule_buf);
return 0; return 0;
} }