You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.0 KiB

  1. From c39a071e7c021f6ff3554aca2758e97b47a9777c Mon Sep 17 00:00:00 2001
  2. From: Steve Grubb <sgrubb@redhat.com>
  3. Date: Tue, 26 Feb 2019 18:33:33 -0500
  4. Subject: [PATCH] Add substitue functions for strndupa & rawmemchr
  5. (cherry picked from commit d579a08bb1cde71f939c13ac6b2261052ae9f77e)
  6. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  7. ---
  8. auparse/auparse.c | 12 +++++++++++-
  9. auparse/interpret.c | 9 ++++++++-
  10. configure.ac | 14 +++++++++++++-
  11. src/ausearch-lol.c | 12 +++++++++++-
  12. 4 files changed, 43 insertions(+), 4 deletions(-)
  13. diff --git a/auparse/auparse.c b/auparse/auparse.c
  14. index 650db02..2e1c737 100644
  15. --- a/auparse/auparse.c
  16. +++ b/auparse/auparse.c
  17. @@ -1,5 +1,5 @@
  18. /* auparse.c --
  19. - * Copyright 2006-08,2012-17 Red Hat Inc., Durham, North Carolina.
  20. + * Copyright 2006-08,2012-19 Red Hat Inc., Durham, North Carolina.
  21. * All Rights Reserved.
  22. *
  23. * This library is free software; you can redistribute it and/or
  24. @@ -1118,6 +1118,16 @@ static int str2event(char *s, au_event_t *e)
  25. return 0;
  26. }
  27. +#ifndef HAVE_STRNDUPA
  28. +static inline char *strndupa(const char *old, size_t n)
  29. +{
  30. + size_t len = strnlen(old, n);
  31. + char *tmp = alloca(len + 1);
  32. + tmp[len] = 0;
  33. + return memcpy(tmp, old, len);
  34. +}
  35. +#endif
  36. +
  37. /* Returns 0 on success and 1 on error */
  38. static int extract_timestamp(const char *b, au_event_t *e)
  39. {
  40. diff --git a/auparse/interpret.c b/auparse/interpret.c
  41. index 51c4a5e..67b7b77 100644
  42. --- a/auparse/interpret.c
  43. +++ b/auparse/interpret.c
  44. @@ -853,6 +853,13 @@ err_out:
  45. return print_escaped(id->val);
  46. }
  47. +// rawmemchr is faster. Let's use it if we have it.
  48. +#ifdef HAVE_RAWMEMCHR
  49. +#define STRCHR rawmemchr
  50. +#else
  51. +#define STRCHR strchr
  52. +#endif
  53. +
  54. static const char *print_proctitle(const char *val)
  55. {
  56. char *out = (char *)print_escaped(val);
  57. @@ -863,7 +870,7 @@ static const char *print_proctitle(const char *val)
  58. // Proctitle has arguments separated by NUL bytes
  59. // We need to write over the NUL bytes with a space
  60. // so that we can see the arguments
  61. - while ((ptr = rawmemchr(ptr, '\0'))) {
  62. + while ((ptr = STRCHR(ptr, '\0'))) {
  63. if (ptr >= end)
  64. break;
  65. *ptr = ' ';
  66. diff --git a/configure.ac b/configure.ac
  67. index 6e345f1..6f3007e 100644
  68. --- a/configure.ac
  69. +++ b/configure.ac
  70. @@ -1,7 +1,7 @@
  71. dnl
  72. define([AC_INIT_NOTICE],
  73. [### Generated automatically using autoconf version] AC_ACVERSION [
  74. -### Copyright 2005-18 Steve Grubb <sgrubb@redhat.com>
  75. +### Copyright 2005-19 Steve Grubb <sgrubb@redhat.com>
  76. ###
  77. ### Permission is hereby granted, free of charge, to any person obtaining a
  78. ### copy of this software and associated documentation files (the "Software"),
  79. @@ -72,6 +72,18 @@ dnl; posix_fallocate is used in audisp-remote
  80. AC_CHECK_FUNCS([posix_fallocate])
  81. dnl; signalfd is needed for libev
  82. AC_CHECK_FUNC([signalfd], [], [ AC_MSG_ERROR([The signalfd system call is necessary for auditd]) ])
  83. +dnl; check if rawmemchr is available
  84. +AC_CHECK_FUNCS([rawmemchr])
  85. +dnl; check if strndupa is available
  86. +AC_LINK_IFELSE(
  87. + [AC_LANG_SOURCE(
  88. + [[
  89. + #define _GNU_SOURCE
  90. + #include <string.h>
  91. + int main() { (void) strndupa("test", 10); return 0; }]])],
  92. + [AC_DEFINE(HAVE_STRNDUPA, 1, [Let us know if we have it or not])],
  93. + []
  94. +)
  95. ALLWARNS=""
  96. ALLDEBUG="-g"
  97. diff --git a/src/ausearch-lol.c b/src/ausearch-lol.c
  98. index 5d17a72..758c33e 100644
  99. --- a/src/ausearch-lol.c
  100. +++ b/src/ausearch-lol.c
  101. @@ -1,6 +1,6 @@
  102. /*
  103. * ausearch-lol.c - linked list of linked lists library
  104. -* Copyright (c) 2008,2010,2014,2016 Red Hat Inc., Durham, North Carolina.
  105. +* Copyright (c) 2008,2010,2014,2016,2019 Red Hat Inc., Durham, North Carolina.
  106. * All Rights Reserved.
  107. *
  108. * This software may be freely redistributed and/or modified under the
  109. @@ -152,6 +152,16 @@ static int compare_event_time(event *e1, event *e2)
  110. return 0;
  111. }
  112. +#ifndef HAVE_STRNDUPA
  113. +static inline char *strndupa(const char *old, size_t n)
  114. +{
  115. + size_t len = strnlen(old, n);
  116. + char *tmp = alloca(len + 1);
  117. + tmp[len] = 0;
  118. + return memcpy(tmp, old, len);
  119. +}
  120. +#endif
  121. +
  122. /*
  123. * This function will look at the line and pick out pieces of it.
  124. */
  125. --
  126. 2.21.0