1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +00:00

Use 64-bit file sizes when resuming scans. See #1742

This commit is contained in:
dmiller
2019-09-16 16:33:04 +00:00
parent 7ce92c68df
commit 7d7f0672d2
3 changed files with 17 additions and 9 deletions

View File

@@ -2335,14 +2335,14 @@ int nmap_main(int argc, char *argv[]) {
int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) { int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) {
char *filestr; char *filestr;
int filelen; s64 filelen;
char nmap_arg_buffer[4096]; /* roughly aligned with arg_parse limit */ char nmap_arg_buffer[4096]; /* roughly aligned with arg_parse limit */
struct in_addr lastip; struct in_addr lastip;
char *p, *q, *found, *lastipstr; /* I love C! */ char *p, *q, *found, *lastipstr; /* I love C! */
/* We mmap it read/write since we will change the last char to a newline if it is not already */ /* We mmap it read/write since we will change the last char to a newline if it is not already */
filestr = mmapfile(fname, &filelen, O_RDWR); filestr = mmapfile(fname, &filelen, O_RDWR);
if (!filestr) { if (!filestr) {
fatal("Could not mmap() %s file. Make sure you have enough rights and the file really exists.", fname); pfatal("Could not mmap() %s file", fname);
} }
if (filelen < 20) { if (filelen < 20) {
@@ -2486,7 +2486,7 @@ int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) {
/* Ensure the log file ends with a newline */ /* Ensure the log file ends with a newline */
filestr[filelen - 1] = '\n'; filestr[filelen - 1] = '\n';
if (munmap(filestr, filelen) != 0) if (munmap(filestr, filelen) != 0)
gh_perror("%s: error in munmap(%p, %u)", __func__, filestr, filelen); gh_perror("%s: error in munmap(%p, %ld)", __func__, filestr, filelen);
return 0; return 0;
} }

View File

@@ -605,7 +605,7 @@ static int open2mmap_flags(int open_flags)
undefined, and errno is set to something appropriate. The user is responsible undefined, and errno is set to something appropriate. The user is responsible
for doing an munmap(ptr, length) when finished with it. openflags should be for doing an munmap(ptr, length) when finished with it. openflags should be
O_RDONLY or O_RDWR, or O_WRONLY. */ O_RDONLY or O_RDWR, or O_WRONLY. */
char *mmapfile(char *fname, int *length, int openflags) { char *mmapfile(char *fname, s64 *length, int openflags) {
struct stat st; struct stat st;
int fd; int fd;
int mmap_flags; int mmap_flags;
@@ -654,9 +654,10 @@ char *mmapfile(char *fname, int *length, int openflags) {
static HANDLE gmap = NULL; static HANDLE gmap = NULL;
char *mmapfile(char *fname, int *length, int openflags) { char *mmapfile(char *fname, s64 *length, int openflags) {
HANDLE fd; HANDLE fd;
DWORD mflags, oflags; DWORD mflags, oflags;
DWORD lowsize, highsize;
char *fileptr; char *fileptr;
if (!length || !fname) { if (!length || !fname) {
@@ -683,11 +684,18 @@ char *mmapfile(char *fname, int *length, int openflags) {
if (!fd) if (!fd)
pfatal ("%s(%u): CreateFile()", __FILE__, __LINE__); pfatal ("%s(%u): CreateFile()", __FILE__, __LINE__);
*length = (int) GetFileSize (fd, NULL); lowsize = GetFileSize (fd, &highsize);
if (lowsize == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) {
pfatal("%s(%u): GetFileSize(), file '%s'", __FILE__, __LINE__, fname);
}
*length = lowsize + highsize << sizeof(DWORD);
if (*length < 0) {
fatal("%s(%u): size too large, file '%s'", __FILE__, __LINE__, fname);
}
gmap = CreateFileMapping (fd, NULL, mflags, 0, 0, NULL); gmap = CreateFileMapping (fd, NULL, mflags, 0, 0, NULL);
if (!gmap) { if (!gmap) {
pfatal("%s(%u): CreateFileMapping(), file '%s', length %d, mflags %08lX", pfatal("%s(%u): CreateFileMapping(), file '%s', length %I64d, mflags %08lX",
__FILE__, __LINE__, fname, *length, mflags); __FILE__, __LINE__, fname, *length, mflags);
} }
@@ -696,7 +704,7 @@ char *mmapfile(char *fname, int *length, int openflags) {
pfatal ("%s(%u): MapViewOfFile()", __FILE__, __LINE__); pfatal ("%s(%u): MapViewOfFile()", __FILE__, __LINE__);
if (o.debugging > 2) { if (o.debugging > 2) {
log_write(LOG_PLAIN, "%s(): fd %08lX, gmap %08lX, fileptr %08lX, length %d\n", log_write(LOG_PLAIN, "%s(): fd %08lX, gmap %08lX, fileptr %08lX, length %I64d\n",
__func__, (DWORD)fd, (DWORD)gmap, (DWORD)fileptr, *length); __func__, (DWORD)fd, (DWORD)gmap, (DWORD)fileptr, *length);
} }

View File

@@ -189,7 +189,7 @@ u8 *parse_hex_string(char *str, size_t *outlen);
int cpe_get_part(const char *cpe); int cpe_get_part(const char *cpe);
char *mmapfile(char *fname, int *length, int openflags); char *mmapfile(char *fname, s64 *length, int openflags);
#ifdef WIN32 #ifdef WIN32
int win32_munmap(char *filestr, int filelen); int win32_munmap(char *filestr, int filelen);