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.

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