mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Use 64-bit file sizes when resuming scans. See #1742
This commit is contained in:
6
nmap.cc
6
nmap.cc
@@ -2335,14 +2335,14 @@ int nmap_main(int argc, char *argv[]) {
|
||||
|
||||
int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) {
|
||||
char *filestr;
|
||||
int filelen;
|
||||
s64 filelen;
|
||||
char nmap_arg_buffer[4096]; /* roughly aligned with arg_parse limit */
|
||||
struct in_addr lastip;
|
||||
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 */
|
||||
filestr = mmapfile(fname, &filelen, O_RDWR);
|
||||
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) {
|
||||
@@ -2486,7 +2486,7 @@ int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) {
|
||||
/* Ensure the log file ends with a newline */
|
||||
filestr[filelen - 1] = '\n';
|
||||
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;
|
||||
}
|
||||
|
||||
18
utils.cc
18
utils.cc
@@ -605,7 +605,7 @@ static int open2mmap_flags(int open_flags)
|
||||
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
|
||||
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;
|
||||
int fd;
|
||||
int mmap_flags;
|
||||
@@ -654,9 +654,10 @@ char *mmapfile(char *fname, int *length, int openflags) {
|
||||
|
||||
static HANDLE gmap = NULL;
|
||||
|
||||
char *mmapfile(char *fname, int *length, int openflags) {
|
||||
char *mmapfile(char *fname, s64 *length, int openflags) {
|
||||
HANDLE fd;
|
||||
DWORD mflags, oflags;
|
||||
DWORD lowsize, highsize;
|
||||
char *fileptr;
|
||||
|
||||
if (!length || !fname) {
|
||||
@@ -683,11 +684,18 @@ char *mmapfile(char *fname, int *length, int openflags) {
|
||||
if (!fd)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -696,7 +704,7 @@ char *mmapfile(char *fname, int *length, int openflags) {
|
||||
pfatal ("%s(%u): MapViewOfFile()", __FILE__, __LINE__);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user