no-strtonum.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. Index: netcat-openbsd-1.89/netcat.c
  2. ===================================================================
  3. --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:17.000000000 -0500
  4. +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:18.000000000 -0500
  5. @@ -67,7 +67,7 @@
  6. /* Command Line Options */
  7. int dflag; /* detached, no stdin */
  8. -unsigned int iflag; /* Interval Flag */
  9. +int iflag; /* Interval Flag */
  10. int jflag; /* use jumbo frames if we can */
  11. int kflag; /* More than one connect */
  12. int lflag; /* Bind to local port */
  13. @@ -108,13 +108,13 @@
  14. main(int argc, char *argv[])
  15. {
  16. int ch, s, ret, socksv;
  17. - char *host, *uport;
  18. + char *host, *uport, *endp;
  19. struct addrinfo hints;
  20. struct servent *sv;
  21. socklen_t len;
  22. struct sockaddr_storage cliaddr;
  23. char *proxy;
  24. - const char *errstr, *proxyhost = "", *proxyport = NULL;
  25. + const char *proxyhost = "", *proxyport = NULL;
  26. struct addrinfo proxyhints;
  27. ret = 1;
  28. @@ -122,6 +122,7 @@
  29. socksv = 5;
  30. host = NULL;
  31. uport = NULL;
  32. + endp = NULL;
  33. sv = NULL;
  34. while ((ch = getopt(argc, argv,
  35. @@ -153,9 +154,9 @@
  36. help();
  37. break;
  38. case 'i':
  39. - iflag = strtonum(optarg, 0, UINT_MAX, &errstr);
  40. - if (errstr)
  41. - errx(1, "interval %s: %s", errstr, optarg);
  42. + iflag = (int)strtoul(optarg, &endp, 10);
  43. + if (iflag < 0 || *endp != '\0')
  44. + errx(1, "interval cannot be negative");
  45. break;
  46. case 'j':
  47. jflag = 1;
  48. @@ -191,9 +192,11 @@
  49. vflag = 1;
  50. break;
  51. case 'w':
  52. - timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
  53. - if (errstr)
  54. - errx(1, "timeout %s: %s", errstr, optarg);
  55. + timeout = (int)strtoul(optarg, &endp, 10);
  56. + if (timeout < 0 || *endp != '\0')
  57. + errx(1, "timeout cannot be negative");
  58. + if (timeout >= (INT_MAX / 1000))
  59. + errx(1, "timeout too large");
  60. timeout *= 1000;
  61. break;
  62. case 'x':
  63. @@ -680,8 +683,7 @@
  64. void
  65. build_ports(char *p)
  66. {
  67. - const char *errstr;
  68. - char *n;
  69. + char *n, *endp;
  70. int hi, lo, cp;
  71. int x = 0;
  72. @@ -693,12 +695,12 @@
  73. n++;
  74. /* Make sure the ports are in order: lowest->highest. */
  75. - hi = strtonum(n, 1, PORT_MAX, &errstr);
  76. - if (errstr)
  77. - errx(1, "port number %s: %s", errstr, n);
  78. - lo = strtonum(p, 1, PORT_MAX, &errstr);
  79. - if (errstr)
  80. - errx(1, "port number %s: %s", errstr, p);
  81. + hi = (int)strtoul(n, &endp, 10);
  82. + if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
  83. + errx(1, "port range not valid");
  84. + lo = (int)strtoul(p, &endp, 10);
  85. + if (lo <= 0 || lo > PORT_MAX || *endp != '\0')
  86. + errx(1, "port range not valid");
  87. if (lo > hi) {
  88. cp = hi;
  89. @@ -729,9 +731,9 @@
  90. }
  91. }
  92. } else {
  93. - hi = strtonum(p, 1, PORT_MAX, &errstr);
  94. - if (errstr)
  95. - errx(1, "port number %s: %s", errstr, p);
  96. + hi = (int)strtoul(p, &endp, 10);
  97. + if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
  98. + errx(1, "port range not valid");
  99. portlist[0] = calloc(1, PORT_MAX_LEN);
  100. if (portlist[0] == NULL)
  101. err(1, NULL);