mirror of
https://github.com/nmap/nmap.git
synced 2026-01-04 05:39:01 +00:00
Fix a stack overrun in ncat's -g option
Because of the postincrement and <= operators, the parsing could write as many as 10 struct in_addr into an array allocated for only 8. Execution would stop because of a later check. Instead, we use preincrement and < operator to do bounds checking, and check for the "too many specified" condition with another call to strtok (which should return NULL if there were no more hops to parse)
This commit is contained in:
@@ -382,8 +382,8 @@ int main(int argc, char *argv[])
|
||||
a, gai_strerror(rc));
|
||||
}
|
||||
o.srcrtes[o.numsrcrtes] = addr.in.sin_addr;
|
||||
} while (o.numsrcrtes++ <= 8 && (a = strtok(NULL, ",")));
|
||||
if (o.numsrcrtes > 8)
|
||||
} while (++o.numsrcrtes < 8 && (a = strtok(NULL, ",")));
|
||||
if (strtok(NULL, ","))
|
||||
bye("Sorry, you gave too many source route hops.");
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user