Skip to content

Commit

Permalink
Add substitue functions for strndupa & rawmemchr
Browse files Browse the repository at this point in the history
  • Loading branch information
RH-steve-grubb committed Feb 26, 2019
1 parent 25e26f4 commit d579a08
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- Allow exclude and user filter by executable name (Ondrej Mosnacek)
- Fix auditd regression where keep_logs is limited by rotate_logs 2 file test
- In ausearch/report fix --end to use midnight time instead of now (#1671338)
- Add substitue functions for strndupa & rawmemchr

2.8.3
- Correct msg function name in LRU debug code
Expand Down
12 changes: 11 additions & 1 deletion auparse/auparse.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* auparse.c --
* Copyright 2006-08,2012-17 Red Hat Inc., Durham, North Carolina.
* Copyright 2006-08,2012-19 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -1119,6 +1119,16 @@ static int str2event(char *s, au_event_t *e)
return 0;
}

#ifndef HAVE_STRNDUPA
static inline char *strndupa(const char *old, size_t n)
{
size_t len = strnlen(old, n);
char *tmp = alloca(len + 1);
tmp[len] = 0;
return memcpy(tmp, old, len);
}
#endif

/* Returns 0 on success and 1 on error */
static int extract_timestamp(const char *b, au_event_t *e)
{
Expand Down
11 changes: 9 additions & 2 deletions auparse/interpret.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* interpret.c - Lookup values to something more readable
* Copyright (c) 2007-09,2011-16,2018 Red Hat Inc., Durham, North Carolina.
* Copyright (c) 2007-09,2011-16,2018-19 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -855,6 +855,13 @@ static const char *print_escaped_ext(const idata *id)
return print_escaped(id->val);
}

// rawmemchr is faster. Let's use it if we have it.
#ifdef HAVE_RAWMEMCHR
#define STRCHR rawmemchr
#else
#define STRCHR strchr
#endif

static const char *print_proctitle(const char *val)
{
char *out = (char *)print_escaped(val);
Expand All @@ -865,7 +872,7 @@ static const char *print_proctitle(const char *val)
// Proctitle has arguments separated by NUL bytes
// We need to write over the NUL bytes with a space
// so that we can see the arguments
while ((ptr = rawmemchr(ptr, '\0'))) {
while ((ptr = STRCHR(ptr, '\0'))) {
if (ptr >= end)
break;
*ptr = ' ';
Expand Down
14 changes: 13 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dnl
define([AC_INIT_NOTICE],
[### Generated automatically using autoconf version] AC_ACVERSION [
### Copyright 2005-18 Steve Grubb <[email protected]>
### Copyright 2005-19 Steve Grubb <[email protected]>
###
### Permission is hereby granted, free of charge, to any person obtaining a
### copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -72,6 +72,18 @@ dnl; posix_fallocate is used in audisp-remote
AC_CHECK_FUNCS([posix_fallocate])
dnl; signalfd is needed for libev
AC_CHECK_FUNC([signalfd], [], [ AC_MSG_ERROR([The signalfd system call is necessary for auditd]) ])
dnl; check if rawmemchr is available
AC_CHECK_FUNCS([rawmemchr])
dnl; check if strndupa is available
AC_LINK_IFELSE(
[AC_LANG_SOURCE(
[[
#define _GNU_SOURCE
#include <string.h>
int main() { (void) strndupa("test", 10); return 0; }]])],
[AC_DEFINE(HAVE_STRNDUPA, 1, [Let us know if we have it or not])],
[]
)

ALLWARNS=""
ALLDEBUG="-g"
Expand Down
12 changes: 11 additions & 1 deletion src/ausearch-lol.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ausearch-lol.c - linked list of linked lists library
* Copyright (c) 2008,2010,2014,2016 Red Hat Inc., Durham, North Carolina.
* Copyright (c) 2008,2010,2014,2016,2019 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* This software may be freely redistributed and/or modified under the
Expand Down Expand Up @@ -152,6 +152,16 @@ static int compare_event_time(event *e1, event *e2)
return 0;
}

#ifndef HAVE_STRNDUPA
static inline char *strndupa(const char *old, size_t n)
{
size_t len = strnlen(old, n);
char *tmp = alloca(len + 1);
tmp[len] = 0;
return memcpy(tmp, old, len);
}
#endif

/*
* This function will look at the line and pick out pieces of it.
*/
Expand Down

0 comments on commit d579a08

Please sign in to comment.