diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-08-14 23:04:24 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-14 23:04:24 +0300 |
| commit | 15b4c1dc052f6682a5480d2e8de4b7ab12f5ed8c (patch) | |
| tree | 5d73a1a40475a69a42f138d327e30c58052652ce /accel-pppd/logs/log_pgsql.c | |
| parent | 4f562467dbdf819395e138617c2a057e02595b9e (diff) | |
| parent | 428333c9bb283ceb998332481867a59e7cea33b4 (diff) | |
| download | accel-ppp-15b4c1dc052f6682a5480d2e8de4b7ab12f5ed8c.tar.gz accel-ppp-15b4c1dc052f6682a5480d2e8de4b7ab12f5ed8c.zip | |
Merge pull request #352 from nuclearcat/stability-fixes
Stability fixes and function unification
Diffstat (limited to 'accel-pppd/logs/log_pgsql.c')
| -rw-r--r-- | accel-pppd/logs/log_pgsql.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/accel-pppd/logs/log_pgsql.c b/accel-pppd/logs/log_pgsql.c index e4b5a9e9..6589da0e 100644 --- a/accel-pppd/logs/log_pgsql.c +++ b/accel-pppd/logs/log_pgsql.c @@ -1,3 +1,13 @@ +/* + * DEPRECATED + * + * This module is scheduled for removal in a future release. It is built + * only when the deprecated LOG_PGSQL_DEPRECATED build flag is given. + * If you depend on it, please object at + * https://github.com/accel-ppp/accel-ppp/issues, otherwise it will be + * deleted. + */ + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,6 +19,7 @@ #include "log.h" #include "list.h" #include "ap_session.h" +#include "utils.h" #include "memdebug.h" @@ -57,20 +68,28 @@ static void unpack_msg(struct log_msg_t *msg) static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) { + const char *username = ses && ses->username ? ses->username : ""; + const char *sessionid = ses && ses->username ? ses->sessionid : ""; struct tm tm; + int pos, len, avail; localtime_r(&msg->timestamp.tv_sec, &tm); strftime(msg->hdr->msg, LOG_CHUNK_SIZE, "%Y-%m-%d %H:%M:%S", &tm); - msg->hdr->len = strlen(msg->hdr->msg) + 1; - if (ses && ses->username) { - strcpy(msg->hdr->msg + msg->hdr->len, ses->username); - msg->hdr->len += strlen(ses->username) + 1; - strcpy(msg->hdr->msg + msg->hdr->len, ses->sessionid); - msg->hdr->len += strlen(ses->sessionid) + 1; - } else - memset(msg->hdr->msg + msg->hdr->len, 0, 2); + pos = strlen(msg->hdr->msg) + 1; + + /* username is peer supplied and may be up to 255 bytes long, + * truncate it to what is left of the chunk, keeping one byte + * for the terminator of the sessionid */ + avail = LOG_CHUNK_SIZE - pos - 1; + len = snprintf(msg->hdr->msg + pos, avail, "%s", username); + pos += min(len, avail - 1) + 1; + avail = LOG_CHUNK_SIZE - pos; + len = snprintf(msg->hdr->msg + pos, avail, "%s", sessionid); + pos += min(len, avail - 1) + 1; + + msg->hdr->len = pos; } static void write_next_msg(void) @@ -284,6 +303,9 @@ static void init(void) { char *opt; + log_warn("log_pgsql: this module is deprecated and is scheduled for removal," + " please object at https://github.com/accel-ppp/accel-ppp/issues if you need it\n"); + spinlock_init(&queue_lock); opt = conf_get_opt("log-pgsql", "conninfo"); |
