diff --git a/docs/changes.txt b/docs/changes.txt index 7cff38539..e9daeddb8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -48,6 +48,7 @@ - Fixed nvapi datatype definition for NvS32 and NvU32 - Fixed WPA/WPA2 cracking in case eapol frame is >= 248 byte - Fixed string not null terminated inside workaround for checking drm driver path +- Fixed string not null terminated when reading maskfiles ## ## Technical diff --git a/include/filehandling.h b/include/filehandling.h index 582599453..39c4d6502 100644 --- a/include/filehandling.h +++ b/include/filehandling.h @@ -14,6 +14,8 @@ u64 count_lines (FILE *fd); int fgetl (FILE *fp, char *line_buf); +size_t superchop_with_length (char *buf, const size_t len); + int in_superchop (char *buf); #endif // _FILEHANDLING_H diff --git a/src/filehandling.c b/src/filehandling.c index 11d37ec17..44a482cfc 100644 --- a/src/filehandling.c +++ b/src/filehandling.c @@ -82,6 +82,37 @@ int fgetl (FILE *fp, char *line_buf) return (line_len); } + +size_t superchop_with_length (char *buf, const size_t len) +{ + size_t new_len = len; + + while (new_len) + { + if (buf[new_len - 1] == '\n') + { + new_len--; + + buf[new_len] = 0; + + continue; + } + + if (buf[new_len - 1] == '\r') + { + new_len--; + + buf[new_len] = 0; + + continue; + } + + break; + } + + return new_len; +} + int in_superchop (char *buf) { size_t len = strlen (buf); @@ -92,6 +123,8 @@ int in_superchop (char *buf) { len--; + buf[len] = 0; + continue; } @@ -99,13 +132,13 @@ int in_superchop (char *buf) { len--; + buf[len] = 0; + continue; } break; } - buf[len] = 0; - return len; } diff --git a/src/mpsp.c b/src/mpsp.c index 8fa11f954..ed80d2b0e 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -567,7 +567,9 @@ static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, return -1; } - const size_t len = in_superchop (mp_file); + mp_file[nread] = 0; + + const size_t len = superchop_with_length (mp_file, nread); if (len == 0) {