202-Improve-pcre2-support.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. From 346b6f8959513320e5b674fd670c49ba2cd43af5 Mon Sep 17 00:00:00 2001
  2. From: Bart Van Assche <bvanassche@acm.org>
  3. Date: Sun, 21 May 2023 16:18:56 -0700
  4. Subject: [PATCH] Improve pcre2 support
  5. Fix compiler warnings. Convert C++ comments to C comments. Make sure that
  6. declarations occur before statements.
  7. ---
  8. agent/mibgroup/host/data_access/swrun.c | 17 ++++------
  9. agent/mibgroup/if-mib/data_access/interface.c | 32 ++++++++++---------
  10. agent/mibgroup/ucd-snmp/proc.c | 13 +++++---
  11. 3 files changed, 31 insertions(+), 31 deletions(-)
  12. --- a/agent/mibgroup/host/data_access/swrun.c
  13. +++ b/agent/mibgroup/host/data_access/swrun.c
  14. @@ -111,10 +111,7 @@ swrun_count_processes_by_regex( char *na
  15. netsnmp_iterator *it;
  16. int i = 0;
  17. #ifdef HAVE_PCRE2_H
  18. - pcre2_match_data *ndx_match;
  19. - int *found_ndx;
  20. - ndx_match = pcre2_match_data_create(30, NULL);
  21. - found_ndx = pcre2_get_ovector_pointer(ndx_match);
  22. + pcre2_match_data *ndx_match = pcre2_match_data_create(30, NULL);
  23. #elif HAVE_PCRE_H
  24. int found_ndx[30];
  25. #endif
  26. @@ -122,22 +119,20 @@ swrun_count_processes_by_regex( char *na
  27. char fullCommand[64 + 128 + 128 + 3];
  28. netsnmp_cache_check_and_reload(swrun_cache);
  29. - if ( !swrun_container || !name || !regexp.regex_ptr )
  30. + if ( !swrun_container || !name || !regexp.regex_ptr ) {
  31. #ifdef HAVE_PCRE2_H
  32. - {
  33. pcre2_match_data_free(ndx_match);
  34. - return 0;
  35. - }
  36. -#else
  37. - return 0; /* or -1 */
  38. #endif
  39. + return 0; /* or -1 */
  40. + }
  41. it = CONTAINER_ITERATOR( swrun_container );
  42. while ((entry = (netsnmp_swrun_entry*)ITERATOR_NEXT( it )) != NULL) {
  43. /* need to assemble full command back so regexps can get full picture */
  44. sprintf(fullCommand, "%s %s", entry->hrSWRunPath, entry->hrSWRunParameters);
  45. #ifdef HAVE_PCRE2_H
  46. - found = pcre2_match(regexp.regex_ptr, fullCommand, strlen(fullCommand), 0, 0, ndx_match, NULL);
  47. + found = pcre2_match(regexp.regex_ptr, (unsigned char *)fullCommand,
  48. + strlen(fullCommand), 0, 0, ndx_match, NULL);
  49. #elif HAVE_PCRE_H
  50. found = pcre_exec(regexp.regex_ptr, NULL, fullCommand, strlen(fullCommand), 0, 0, found_ndx, 30);
  51. #endif
  52. --- a/agent/mibgroup/if-mib/data_access/interface.c
  53. +++ b/agent/mibgroup/if-mib/data_access/interface.c
  54. @@ -844,12 +844,8 @@ int netsnmp_access_interface_max_reached
  55. int netsnmp_access_interface_include(const char *name)
  56. {
  57. netsnmp_include_if_list *if_ptr;
  58. -#if defined(HAVE_PCRE2_H)
  59. - //pcre_exec->pcre2_match
  60. - //ovector->pcre2_match_data
  61. - pcre2_match_data *ndx_match;
  62. - ndx_match = pcre2_match_data_create(3, NULL);
  63. - int *found_ndx = pcre2_get_ovector_pointer(ndx_match);
  64. +#if defined(HAVE_PCRE2_H)
  65. + pcre2_match_data *ndx_match = pcre2_match_data_create(3, NULL);
  66. #elif defined(HAVE_PCRE_H)
  67. int found_ndx[3];
  68. #endif
  69. @@ -867,8 +863,8 @@ int netsnmp_access_interface_include(con
  70. for (if_ptr = include_list; if_ptr; if_ptr = if_ptr->next) {
  71. #if defined(HAVE_PCRE2_H)
  72. - if (pcre2_match(if_ptr->regex_ptr, name, strlen(name), 0, 0,
  73. - ndx_match, NULL) >= 0) {
  74. + if (pcre2_match(if_ptr->regex_ptr, (const unsigned char *)name,
  75. + strlen(name), 0, 0, ndx_match, NULL) >= 0) {
  76. pcre2_match_data_free(ndx_match);
  77. return TRUE;
  78. }
  79. @@ -1000,11 +996,13 @@ _parse_include_if_config(const char *tok
  80. netsnmp_include_if_list *if_ptr, *if_new;
  81. char *name, *st;
  82. #if defined(HAVE_PCRE2_H)
  83. - //we can only get the message upon calling pcre2_error_message.
  84. - // so an additional variable is required.
  85. + /*
  86. + * We can only get the message upon calling pcre2_error_message.
  87. + * so an additional variable is required.
  88. + */
  89. int pcre2_err_code;
  90. - unsigned char pcre2_error[128];
  91. - int pcre2_error_offset;
  92. + char pcre2_error[128];
  93. + size_t pcre2_error_offset;
  94. #elif defined(HAVE_PCRE_H)
  95. const char *pcre_error;
  96. int pcre_error_offset;
  97. @@ -1038,10 +1036,14 @@ _parse_include_if_config(const char *tok
  98. goto err;
  99. }
  100. #if defined(HAVE_PCRE2_H)
  101. - if_new->regex_ptr = pcre2_compile(if_new->name, PCRE2_ZERO_TERMINATED, 0,
  102. - &pcre2_err_code, &pcre2_error_offset, NULL);
  103. + if_new->regex_ptr = pcre2_compile((const unsigned char *)if_new->name,
  104. + PCRE2_ZERO_TERMINATED, 0,
  105. + &pcre2_err_code, &pcre2_error_offset,
  106. + NULL);
  107. if (!if_new->regex_ptr) {
  108. - pcre2_get_error_message(pcre2_err_code, pcre2_error, 128);
  109. + pcre2_get_error_message(pcre2_err_code,
  110. + (unsigned char *)pcre2_error,
  111. + sizeof(pcre2_error));
  112. config_perror(pcre2_error);
  113. goto err;
  114. }
  115. --- a/agent/mibgroup/ucd-snmp/proc.c
  116. +++ b/agent/mibgroup/ucd-snmp/proc.c
  117. @@ -226,15 +226,17 @@ proc_parse_config(const char *token, cha
  118. #if defined(HAVE_PCRE2_H) || defined(HAVE_PCRE_H)
  119. cptr = skip_not_white(cptr);
  120. if ((cptr = skip_white(cptr))) {
  121. - DEBUGMSGTL(("ucd-snmp/regexp_proc", "Loading regex %s\n", cptr));
  122. #ifdef HAVE_PCRE2_H
  123. - unsigned char pcre2_error_msg[128];
  124. + char pcre2_error_msg[128];
  125. int pcre2_err_code;
  126. - int pcre2_error_offset;
  127. + size_t pcre2_error_offset;
  128. + DEBUGMSGTL(("ucd-snmp/regexp_proc", "Loading regex %s\n", cptr));
  129. (*procp)->regexp.regex_ptr =
  130. - pcre2_compile(cptr, PCRE2_ZERO_TERMINATED, 0, &pcre2_err_code, &pcre2_error_offset, NULL);
  131. - pcre2_get_error_message(pcre2_err_code, pcre2_error_msg, 128);
  132. + pcre2_compile((const unsigned char *)cptr, PCRE2_ZERO_TERMINATED, 0, &pcre2_err_code, &pcre2_error_offset, NULL);
  133. + pcre2_get_error_message(pcre2_err_code,
  134. + (unsigned char *)pcre2_error_msg,
  135. + sizeof(pcre2_error_msg));
  136. if ((*procp)->regexp.regex_ptr == NULL) {
  137. config_perror(pcre2_error_msg);
  138. }
  139. @@ -242,6 +244,7 @@ proc_parse_config(const char *token, cha
  140. const char *pcre_error;
  141. int pcre_error_offset;
  142. + DEBUGMSGTL(("ucd-snmp/regexp_proc", "Loading regex %s\n", cptr));
  143. (*procp)->regexp.regex_ptr =
  144. pcre_compile(cptr, 0, &pcre_error, &pcre_error_offset, NULL);
  145. if ((*procp)->regexp.regex_ptr == NULL) {