summaryrefslogtreecommitdiff
path: root/src/map/channel.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-04-19 11:32:04 +0200
committerHaru <haru@dotalux.com>2016-04-23 18:41:55 +0200
commit3af03d2a2e8f2054f9a44e272505b1a74d6bdaf6 (patch)
tree0de82d83d0ba15e12b48ea8eeb3ac6dd2471a47f /src/map/channel.c
parente69e8c5315d0b95ecbe3072c11ba60e108ed9ec5 (diff)
downloadhercules-3af03d2a2e8f2054f9a44e272505b1a74d6bdaf6.tar.gz
hercules-3af03d2a2e8f2054f9a44e272505b1a74d6bdaf6.tar.bz2
hercules-3af03d2a2e8f2054f9a44e272505b1a74d6bdaf6.tar.xz
hercules-3af03d2a2e8f2054f9a44e272505b1a74d6bdaf6.zip
Improved parsing of the server name/port in the irc bot configuration
Fixes a VS2015 warning Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/channel.c')
-rw-r--r--src/map/channel.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/map/channel.c b/src/map/channel.c
index 3d1b3f975..e4e3d069d 100644
--- a/src/map/channel.c
+++ b/src/map/channel.c
@@ -640,52 +640,47 @@ void read_channels_config(void)
const char *irc_server, *irc_channel,
*irc_nick, *irc_nick_pw;
int irc_use_ghost = 0;
- if( libconfig->setting_lookup_string(settings, "irc_channel_network", &irc_server) ) {
- if( !strstr(irc_server,":") ) {
+ if (!libconfig->setting_lookup_string(settings, "irc_channel_network", &irc_server)) {
+ channel->config->irc = false;
+ ShowWarning("channels.conf : irc channel enabled but irc_channel_network wasn't found, disabling irc channel...\n");
+ } else {
+ char *server = aStrdup(irc_server);
+ char *port = strchr(server, ':');
+ if (port == NULL) {
channel->config->irc = false;
- ShowWarning("channels.conf : network port wasn't found in 'irc_channel_network', disabling irc channel...\n");
+ ShowWarning("channels.conf: network port wasn't found in 'irc_channel_network', disabling irc channel...\n");
+ } else if ((size_t)(port-server) > sizeof channel->config->irc_server - 1) {
+ channel->config->irc = false;
+ ShowWarning("channels.conf: server name is too long in 'irc_channel_network', disabling irc channel...\n");
} else {
- unsigned char d = 0, dlen = strlen(irc_server);
- char server[40];
- if (dlen > 39)
- dlen = 39;
- memset(server, '\0', sizeof(server));
-
- for(d = 0; d < dlen; d++) {
- if(irc_server[d] == ':') {
- memcpy(server, irc_server, d);
- safestrncpy(channel->config->irc_server, server, 40);
- memcpy(server, &irc_server[d+1], dlen - d - 1);
- channel->config->irc_server_port = atoi(server);
- break;
- }
- }
+ *port = '\0';
+ port++;
+ safestrncpy(channel->config->irc_server, server, sizeof channel->config->irc_server);
+ channel->config->irc_server_port = atoi(port);
}
- } else {
- channel->config->irc = false;
- ShowWarning("channels.conf : irc channel enabled but irc_channel_network wasn't found, disabling irc channel...\n");
+ aFree(server);
}
- if( libconfig->setting_lookup_string(settings, "irc_channel_channel", &irc_channel) )
+ if (libconfig->setting_lookup_string(settings, "irc_channel_channel", &irc_channel)) {
safestrncpy(channel->config->irc_channel, irc_channel, 50);
- else {
+ } else {
channel->config->irc = false;
ShowWarning("channels.conf : irc channel enabled but irc_channel_channel wasn't found, disabling irc channel...\n");
}
- if( libconfig->setting_lookup_string(settings, "irc_channel_nick", &irc_nick) ) {
- if( strcmpi(irc_nick,"Hercules_chSysBot") == 0 ) {
+ if (libconfig->setting_lookup_string(settings, "irc_channel_nick", &irc_nick)) {
+ if (strcmpi(irc_nick,"Hercules_chSysBot") == 0) {
sprintf(channel->config->irc_nick, "Hercules_chSysBot%d",rnd()%777);
- } else
+ } else {
safestrncpy(channel->config->irc_nick, irc_nick, 40);
+ }
} else {
channel->config->irc = false;
ShowWarning("channels.conf : irc channel enabled but irc_channel_nick wasn't found, disabling irc channel...\n");
}
- if( libconfig->setting_lookup_string(settings, "irc_channel_nick_pw", &irc_nick_pw) ) {
+ if (libconfig->setting_lookup_string(settings, "irc_channel_nick_pw", &irc_nick_pw)) {
safestrncpy(channel->config->irc_nick_pw, irc_nick_pw, 30);
config_setting_lookup_bool(settings, "irc_channel_use_ghost", &irc_use_ghost);
channel->config->irc_use_ghost = irc_use_ghost;
}
-
}
libconfig->setting_lookup_bool(settings, "map_local_channel_autojoin", &local_autojoin);