Skip to content

Handle newlines correctly when error_log set to "syslog" #2674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Zend/zend_smart_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static zend_always_inline void smart_string_setl(smart_string *dest, char *src,
dest->c = src;
}

static zend_always_inline void smart_string_reset(smart_string *str) {
str->len = 0;
}

#endif

/*
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
strlcat.c explicit_bzero.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
network.c php_open_temporary_file.c \
output.c getopt.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
output.c getopt.c php_syslog.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

php_syslog.c should also be added to the Windows build system in win32/build/config.w32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


PHP_ADD_SOURCES_X(main, fastcgi.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, PHP_FASTCGI_OBJS, no)

Expand Down
81 changes: 81 additions & 0 deletions main/php_syslog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 2017 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Philip Prindeville <philipp@redfish-solutions.com> |
+----------------------------------------------------------------------+
*/

/* $Id$ */

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "php.h"
#include "php_syslog.h"

#include "zend.h"
#include "zend_smart_string.h"

/*
* The SCO OpenServer 5 Development System (not the UDK)
* defines syslog to std_syslog.
*/

#ifdef HAVE_STD_SYSLOG
#define syslog std_syslog
#endif

PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
{
const char *ptr;
unsigned char c;
smart_string fbuf = {0};
smart_string sbuf = {0};
va_list args;

va_start(args, format);
zend_printf_to_smart_string(&fbuf, format, args);
smart_string_0(&fbuf);
va_end(args);

for (ptr = fbuf.c; ; ++ptr) {
c = *ptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be inside the for I guess :)

if (c == '\0') {
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
break;
}

if (c != '\n')
smart_string_appendc(&sbuf, c);
else {
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
smart_string_reset(&sbuf);
}
}

smart_string_free(&fbuf);
smart_string_free(&sbuf);
}

/* }}} */

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
22 changes: 5 additions & 17 deletions main/php_syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef PHP_SYSLOG_H
#define PHP_SYSLOG_H

#include "php.h"

#ifdef PHP_WIN32
#include "win32/syslog.h"
#else
Expand All @@ -30,26 +32,12 @@
#endif
#endif

/*
* The SCO OpenServer 5 Development System (not the UDK)
* defines syslog to std_syslog.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be kept somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


#ifdef syslog

#ifdef HAVE_STD_SYSLOG
#define php_syslog std_syslog
#endif

#undef syslog
BEGIN_EXTERN_C()
PHPAPI void php_syslog(int, const char *format, ...);
END_EXTERN_C()

#endif

#ifndef php_syslog
#define php_syslog syslog
#endif

#endif
/*
* Local variables:
* tab-width: 4
Expand Down
3 changes: 2 additions & 1 deletion win32/build/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
php_open_temporary_file.c output.c internal_functions.c php_sprintf.c \
php_syslog.c");
ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");

AC_DEFINE('HAVE_STRNLEN', 1);
Expand Down