Advertisement
bonsaiviking

Optimize fingerprint parsing

Oct 18th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.64 KB | None | 0 0
  1. diff --git a/osscan.cc b/osscan.cc
  2. index 9bc696d..4fd740e 100644
  3. --- a/osscan.cc
  4. +++ b/osscan.cc
  5. @@ -156,28 +156,28 @@ extern NmapOps o;
  6.     certain string, it allocates memory and stores a copy of the string in a
  7.     static pool. Thereafter it will return a pointer to the saved string instead
  8.     of allocating memory for an identical one. */
  9. -const char *string_pool_insert(const char *s)
  10. +const char *string_pool_insert(const char *s, const char *t)
  11.  {
  12.    static std::set<std::string> pool;
  13.    static std::pair<std::set<std::string>::iterator, bool> pair;
  14.  
  15. -  pair = pool.insert(s);
  16. +  if (t) {
  17. +      pair = pool.insert(std::string(s, t));
  18. +  }
  19. +  else {
  20. +      pair = pool.insert(s);
  21. +  }
  22.  
  23.    return pair.first->c_str();
  24.  }
  25.  
  26. -const char *string_pool_substr(const char *s, const char *t)
  27. -{
  28. -  return string_pool_insert(std::string(s, t).c_str());
  29. -}
  30. -
  31.  const char *string_pool_substr_strip(const char *s, const char *t) {
  32.    while (isspace((int) (unsigned char) *s))
  33.      s++;
  34.    while (t > s && isspace((int) (unsigned char) *(t - 1)))
  35.      t--;
  36.  
  37. -  return string_pool_substr(s, t);
  38. +  return string_pool_insert(s, t);
  39.  }
  40.  
  41.  /* Skip over whitespace to find the beginning of a word, then read until the
  42. @@ -194,7 +194,7 @@ static const char *string_pool_strip_word(const char *s) {
  43.    if (s == t)
  44.      return NULL;
  45.  
  46. -  return string_pool_substr(s, t);
  47. +  return string_pool_insert(s, t);
  48.  }
  49.  
  50.  /* Format a string with sprintf and insert it with string_pool_insert. */
  51. @@ -799,14 +799,14 @@ static std::vector<struct AVal> str2AVal(const char *str) {
  52.      if (!q) {
  53.        fatal("Parse error with AVal string (%s) in nmap-os-db file", str);
  54.      }
  55. -    av.attribute = string_pool_substr(p, q);
  56. +    av.attribute = string_pool_insert(p, q);
  57.      p = q+1;
  58.      if (i < count - 1) {
  59.        q = strchr(p, '%');
  60.        if (!q) {
  61.          fatal("Parse error with AVal string (%s) in nmap-os-db file", str);
  62.        }
  63. -      av.value = string_pool_substr(p, q);
  64. +      av.value = string_pool_insert(p, q);
  65.      } else {
  66.        av.value = string_pool_insert(p);
  67.      }
  68. diff --git a/osscan.h b/osscan.h
  69. index 5437d6b..bf33ece 100644
  70. --- a/osscan.h
  71. +++ b/osscan.h
  72. @@ -148,7 +148,7 @@
  73.  /* The OS database consists of many small strings, many of which appear
  74.     thousands of times. It pays to allocate memory only once for each unique
  75.     string, and have all references point at the one allocated value. */
  76. -const char *string_pool_insert(const char *s);
  77. +const char *string_pool_insert(const char *s, const char *t=NULL);
  78.  const char *string_pool_sprintf(const char *fmt, ...);
  79.  
  80.  const char *fp2ascii(FingerPrint *FP);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement