From 1c96824cb328957c686c3c392dfa27487db5a16c Mon Sep 17 00:00:00 2001 From: vraatikka Date: Wed, 13 Nov 2013 22:08:10 +0200 Subject: [PATCH] log_manager.cc Declared program_invocation_name, and program_invocation_short_name. They are used as identifier strings in syslog logging in cases where log_manager is not initialized explicitly and/or the caller hasn't specified program name as one of the arguments in arguments array. Fixed memory corruption. Length of sequence number of file name was calculated to as one too short and one byte was written to unallocated memory. Freed also the linkpath in cases where at least one of the log files is written to shm and a symlink is added to log directory. mysql_client.c Added debug check for protocol pointer because of memory issues in mysql_client.c --- log_manager/log_manager.cc | 27 +++++++++++++++++++++----- server/modules/protocol/mysql_client.c | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index fd34aa73b..ec090c043 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -37,6 +37,13 @@ #define MAX_PATHLEN 512 #define MAXNBLOCKBUFS 10 +/** for procname */ +#define _GNU_SOURCE + +extern char *program_invocation_name; +extern char *program_invocation_short_name; + + /** * BUFSIZ comes from the system. It equals with block size or * its multiplication. @@ -58,8 +65,10 @@ const char* shm_pathname = "/dev/shm"; /** Logfile ids from call argument '-s' */ char* shmem_id_str = NULL; -char* syslog_id_str = NULL; +/** Errors are written to syslog too by default */ +char* syslog_id_str = strdup("LOGFILE_ERROR"); char* syslog_ident_str = NULL; + /** * Global log manager pointer and lock variable. * lmlock protects logmanager access. @@ -1402,6 +1411,10 @@ static bool fnames_conf_init( case 'l': /** record list of log file ids for syslogged */ + if (syslog_id_str != NULL) + { + free (syslog_id_str); + } syslog_id_str = optarg; break; @@ -1446,8 +1459,11 @@ static bool fnames_conf_init( strdup(get_logpath_default()) : fn->fn_logpath; /** Set identity string for syslog if it is not set in config.*/ - syslog_ident_str = (syslog_ident_str == NULL) ? - syslog_ident_str = strdup(*argv) : syslog_ident_str; + syslog_ident_str = + (syslog_ident_str == NULL ? + (argv == NULL ? strdup(program_invocation_short_name) : + strdup(*argv)) : + syslog_ident_str); /* ss_dfprintf(stderr, "\n\n\tCommand line : "); for (i=0; ilf_filepath != NULL) free(lf->lf_filepath); + if (lf->lf_linkpath != NULL) free(lf->lf_linkpath); if (lf->lf_name_prefix != NULL) free(lf->lf_name_prefix); if (lf->lf_name_suffix != NULL) free(lf->lf_name_suffix); if (lf->lf_full_link_name != NULL) free(lf->lf_full_link_name); diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index 162148abc..8b593ee57 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -361,6 +361,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) { CHK_DCB(dcb); protocol = DCB_PROTOCOL(dcb, MySQLProtocol); + CHK_PROTOCOL(protocol); client_data = (MYSQL_session *)calloc(1, sizeof(MYSQL_session)); dcb->data = client_data;