1From d5a4b800a696b8b8d2c0f0bad098b1a8ff94333f Mon Sep 17 00:00:00 2001 2From: Steve Grubb <sgrubb@redhat.com> 3Date: Tue, 26 Feb 2019 18:33:33 -0500 4Subject: [PATCH] Add substitue functions for strndupa & rawmemchr 5 6Upstream-Status: Backport 7[https://github.com/linux-audit/audit-userspace/commit/d579a08bb1cde71f939c13ac6b2261052ae9f77e] 8--- 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(-) 14 15diff --git a/auparse/auparse.c b/auparse/auparse.c 16index 650db02..2e1c737 100644 17--- a/auparse/auparse.c 18+++ b/auparse/auparse.c 19@@ -1,5 +1,5 @@ 20 /* 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. 24 * 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) 27 return 0; 28 } 29 30+#ifndef HAVE_STRNDUPA 31+static inline char *strndupa(const char *old, size_t n) 32+{ 33+ size_t len = strnlen(old, n); 34+ char *tmp = alloca(len + 1); 35+ tmp[len] = 0; 36+ return memcpy(tmp, old, len); 37+} 38+#endif 39+ 40 /* Returns 0 on success and 1 on error */ 41 static int extract_timestamp(const char *b, au_event_t *e) 42 { 43diff --git a/auparse/interpret.c b/auparse/interpret.c 44index 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); 49 } 50 51+// rawmemchr is faster. Let's use it if we have it. 52+#ifdef HAVE_RAWMEMCHR 53+#define STRCHR rawmemchr 54+#else 55+#define STRCHR strchr 56+#endif 57+ 58 static const char *print_proctitle(const char *val) 59 { 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'))) { 67 if (ptr >= end) 68 break; 69 *ptr = ' '; 70diff --git a/configure.ac b/configure.ac 71index 6e345f1..6f3007e 100644 72--- a/configure.ac 73+++ b/configure.ac 74@@ -1,7 +1,7 @@ 75 dnl 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> 80 ### 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 90+AC_LINK_IFELSE( 91+ [AC_LANG_SOURCE( 92+ [[ 93+ #define _GNU_SOURCE 94+ #include <string.h> 95+ int main() { (void) strndupa("test", 10); return 0; }]])], 96+ [AC_DEFINE(HAVE_STRNDUPA, 1, [Let us know if we have it or not])], 97+ [] 98+) 99 100 ALLWARNS="" 101 ALLDEBUG="-g" 102diff --git a/src/ausearch-lol.c b/src/ausearch-lol.c 103index 5d17a72..758c33e 100644 104--- a/src/ausearch-lol.c 105+++ b/src/ausearch-lol.c 106@@ -1,6 +1,6 @@ 107 /* 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. 112 * 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) 115 return 0; 116 } 117 118+#ifndef HAVE_STRNDUPA 119+static inline char *strndupa(const char *old, size_t n) 120+{ 121+ size_t len = strnlen(old, n); 122+ char *tmp = alloca(len + 1); 123+ tmp[len] = 0; 124+ return memcpy(tmp, old, len); 125+} 126+#endif 127+ 128 /* 129 * This function will look at the line and pick out pieces of it. 130 */ 131-- 1322.17.1 133 134