1 From bdcdc3dff4469aac88e718bd15958d5ed4b9392a 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
6 Upstream-Status: Backport
7 [https://github.com/linux-audit/audit-userspace/commit/d579a08bb1cde71f939c13ac6b2261052ae9f77e]
9 auparse/auparse.c | 12 +++++++++++-
10 auparse/interpret.c | 9 ++++++++-
11 configure.ac | 14 +++++++++++++-
12 src/ausearch-lol.c | 12 +++++++++++-
13 4 files changed, 43 insertions(+), 4 deletions(-)
15 diff --git a/auparse/auparse.c b/auparse/auparse.c
16 index 650db02..2e1c737 100644
17 --- a/auparse/auparse.c
18 +++ b/auparse/auparse.c
21 - * Copyright 2006-08,2012-17 Red Hat Inc., Durham, North Carolina.
22 + * Copyright 2006-08,2012-19 Red Hat Inc., Durham, North Carolina.
23 * All Rights Reserved.
25 * This library is free software; you can redistribute it and/or
26 @@ -1118,6 +1118,16 @@ static int str2event(char *s, au_event_t *e)
30 +#ifndef HAVE_STRNDUPA
31 +static inline char *strndupa(const char *old, size_t n)
33 + size_t len = strnlen(old, n);
34 + char *tmp = alloca(len + 1);
36 + return memcpy(tmp, old, len);
40 /* Returns 0 on success and 1 on error */
41 static int extract_timestamp(const char *b, au_event_t *e)
43 diff --git a/auparse/interpret.c b/auparse/interpret.c
44 index 51c4a5e..67b7b77 100644
45 --- a/auparse/interpret.c
46 +++ b/auparse/interpret.c
47 @@ -853,6 +853,13 @@ err_out:
48 return print_escaped(id->val);
51 +// rawmemchr is faster. Let's use it if we have it.
52 +#ifdef HAVE_RAWMEMCHR
53 +#define STRCHR rawmemchr
55 +#define STRCHR strchr
58 static const char *print_proctitle(const char *val)
60 char *out = (char *)print_escaped(val);
61 @@ -863,7 +870,7 @@ static const char *print_proctitle(const char *val)
62 // Proctitle has arguments separated by NUL bytes
63 // We need to write over the NUL bytes with a space
64 // so that we can see the arguments
65 - while ((ptr = rawmemchr(ptr, '\0'))) {
66 + while ((ptr = STRCHR(ptr, '\0'))) {
70 diff --git a/configure.ac b/configure.ac
71 index 54bdbf1..aef07fb 100644
76 define([AC_INIT_NOTICE],
77 [### Generated automatically using autoconf version] AC_ACVERSION [
78 -### Copyright 2005-18 Steve Grubb <sgrubb@redhat.com>
79 +### Copyright 2005-19 Steve Grubb <sgrubb@redhat.com>
81 ### Permission is hereby granted, free of charge, to any person obtaining a
82 ### copy of this software and associated documentation files (the "Software"),
83 @@ -72,6 +72,18 @@ dnl; posix_fallocate is used in audisp-remote
84 AC_CHECK_FUNCS([posix_fallocate])
85 dnl; signalfd is needed for libev
86 AC_CHECK_FUNC([signalfd], [], [ AC_MSG_ERROR([The signalfd system call is necessary for auditd]) ])
87 +dnl; check if rawmemchr is available
88 +AC_CHECK_FUNCS([rawmemchr])
89 +dnl; check if strndupa is available
95 + int main() { (void) strndupa("test", 10); return 0; }]])],
96 + [AC_DEFINE(HAVE_STRNDUPA, 1, [Let us know if we have it or not])],
102 diff --git a/src/ausearch-lol.c b/src/ausearch-lol.c
103 index 5d17a72..758c33e 100644
104 --- a/src/ausearch-lol.c
105 +++ b/src/ausearch-lol.c
108 * ausearch-lol.c - linked list of linked lists library
109 -* Copyright (c) 2008,2010,2014,2016 Red Hat Inc., Durham, North Carolina.
110 +* Copyright (c) 2008,2010,2014,2016,2019 Red Hat Inc., Durham, North Carolina.
111 * All Rights Reserved.
113 * This software may be freely redistributed and/or modified under the
114 @@ -152,6 +152,16 @@ static int compare_event_time(event *e1, event *e2)
118 +#ifndef HAVE_STRNDUPA
119 +static inline char *strndupa(const char *old, size_t n)
121 + size_t len = strnlen(old, n);
122 + char *tmp = alloca(len + 1);
124 + return memcpy(tmp, old, len);
129 * This function will look at the line and pick out pieces of it.