From 7c3cdc81f7c7397b545322e0215f3e93526469ca Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Thu, 27 Jul 2017 21:58:22 -0400 Subject: Fix compiler warnings on Fedora 26 / GCC 7. GCC 7 has added capability to produce warnings, this fixes most of those warnings. The specific warnings are disabled in a few places: * app_voicemail.c: truncation of paths more than 4096 chars in many places. * chan_mgcp.c: callid truncated to 80 chars. * cdr.c: two userfields are combined to cdr copy, fix would break ABI. * tcptls.c: ignore use of deprecated method SSLv3_client_method(). ASTERISK-27156 #close Change-Id: I65f280e7d3cfad279d16f41823a4d6fddcbc4c88 --- main/Makefile | 3 ++- main/ast_expr2.c | 6 ++---- main/ast_expr2.y | 6 ++---- main/asterisk.c | 7 +++++-- main/ccss.c | 2 +- main/cli.c | 4 ++-- main/libasteriskssl.c | 24 +++++++++++++----------- main/manager.c | 2 +- main/stdtime/localtime.c | 2 +- main/utils.c | 2 +- 10 files changed, 30 insertions(+), 28 deletions(-) (limited to 'main') diff --git a/main/Makefile b/main/Makefile index 4fb6a0131..d816443d0 100644 --- a/main/Makefile +++ b/main/Makefile @@ -140,6 +140,7 @@ endif $(CMD_PREFIX) rm $@.fix ast_expr2f.o: _ASTCFLAGS+=-Wno-unused +cdr.o: _ASTCFLAGS+=-Wno-format-truncation testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c @@ -314,7 +315,7 @@ endif endif -tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) +tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -Wno-deprecated-declarations $(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ) @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS) diff --git a/main/ast_expr2.c b/main/ast_expr2.c index 4b06ffe91..093b441d0 100644 --- a/main/ast_expr2.c +++ b/main/ast_expr2.c @@ -2635,13 +2635,11 @@ to_string (struct val *vp) if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string) return; - tmp = malloc ((size_t)25); - if (tmp == NULL) { - ast_log(LOG_WARNING,"malloc() failed\n"); + if (asprintf(&tmp, FP___PRINTF, vp->u.i) == -1) { + ast_log(LOG_WARNING, "asprintf() failed\n"); return; } - sprintf(tmp, FP___PRINTF, vp->u.i); vp->type = AST_EXPR_string; vp->u.s = tmp; } diff --git a/main/ast_expr2.y b/main/ast_expr2.y index f516291f9..3c8943094 100644 --- a/main/ast_expr2.y +++ b/main/ast_expr2.y @@ -628,13 +628,11 @@ to_string (struct val *vp) if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string) return; - tmp = malloc ((size_t)25); - if (tmp == NULL) { - ast_log(LOG_WARNING,"malloc() failed\n"); + if (asprintf(&tmp, FP___PRINTF, vp->u.i) == -1) { + ast_log(LOG_WARNING, "asprintf() failed\n"); return; } - sprintf(tmp, FP___PRINTF, vp->u.i); vp->type = AST_EXPR_string; vp->u.s = tmp; } diff --git a/main/asterisk.c b/main/asterisk.c index a302836a4..0a131fda9 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -393,6 +393,9 @@ static void ast_el_write_default_histfile(void); static void asterisk_daemon(int isroot, const char *runuser, const char *rungroup); +#define DEFAULT_MONITOR_DIR DEFAULT_SPOOL_DIR "/monitor" +#define DEFAULT_RECORDING_DIR DEFAULT_SPOOL_DIR "/recording" + struct _cfg_paths { char config_dir[PATH_MAX]; char module_dir[PATH_MAX]; @@ -3526,8 +3529,8 @@ static void ast_readconfig(void) ast_copy_string(cfg_paths.config_dir, DEFAULT_CONFIG_DIR, sizeof(cfg_paths.config_dir)); ast_copy_string(cfg_paths.spool_dir, DEFAULT_SPOOL_DIR, sizeof(cfg_paths.spool_dir)); ast_copy_string(cfg_paths.module_dir, DEFAULT_MODULE_DIR, sizeof(cfg_paths.module_dir)); - snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir), "%s/monitor", cfg_paths.spool_dir); - snprintf(cfg_paths.recording_dir, sizeof(cfg_paths.recording_dir), "%s/recording", cfg_paths.spool_dir); + ast_copy_string(cfg_paths.monitor_dir, DEFAULT_MONITOR_DIR, sizeof(cfg_paths.monitor_dir)); + ast_copy_string(cfg_paths.recording_dir, DEFAULT_RECORDING_DIR, sizeof(cfg_paths.recording_dir)); ast_copy_string(cfg_paths.var_dir, DEFAULT_VAR_DIR, sizeof(cfg_paths.var_dir)); ast_copy_string(cfg_paths.data_dir, DEFAULT_DATA_DIR, sizeof(cfg_paths.data_dir)); ast_copy_string(cfg_paths.log_dir, DEFAULT_LOG_DIR, sizeof(cfg_paths.log_dir)); diff --git a/main/ccss.c b/main/ccss.c index f96d7aa1d..a9d15b072 100644 --- a/main/ccss.c +++ b/main/ccss.c @@ -3546,7 +3546,7 @@ struct ast_cc_monitor *ast_cc_get_monitor_by_recall_core_id(const int core_id, c */ static void cc_unique_append(struct ast_str **str, const char *dialstring) { - char dialstring_search[AST_CHANNEL_NAME]; + char dialstring_search[AST_CHANNEL_NAME + 1]; if (ast_strlen_zero(dialstring)) { /* No dialstring to append. */ diff --git a/main/cli.c b/main/cli.c index 06f2d55b2..ef86e256a 100644 --- a/main/cli.c +++ b/main/cli.c @@ -372,7 +372,7 @@ static char *complete_number(const char *partial, unsigned int min, unsigned int int i, count = 0; unsigned int prospective[2]; unsigned int part = strtoul(partial, NULL, 10); - char next[12]; + char next[13]; if (part < min || part > max) { return NULL; @@ -1031,7 +1031,7 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar it_chans = ao2_iterator_init(channels, 0); for (; (msg = ao2_iterator_next(&it_chans)); ao2_ref(msg, -1)) { struct ast_channel_snapshot *cs = stasis_message_data(msg); - char durbuf[10] = "-"; + char durbuf[16] = "-"; if (!count) { if ((concise || verbose) && !ast_tvzero(cs->creationtime)) { diff --git a/main/libasteriskssl.c b/main/libasteriskssl.c index 9da63de4c..8b19e247d 100644 --- a/main/libasteriskssl.c +++ b/main/libasteriskssl.c @@ -29,20 +29,21 @@ #include "asterisk.h" +#include "asterisk/_private.h" /* ast_ssl_init() */ + #ifdef HAVE_OPENSSL #include #include #endif -#include +#if defined(HAVE_OPENSSL) && \ + !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) -#include "asterisk/_private.h" /* ast_ssl_init() */ +#include #include "asterisk/utils.h" #include "asterisk/lock.h" -#ifdef HAVE_OPENSSL - #define get_OpenSSL_function(func) do { real_##func = dlsym(RTLD_NEXT, __stringify(func)); } while(0) static int startup_complete; @@ -72,7 +73,6 @@ static void ssl_lock(int mode, int n, const char *file, int line) } } -#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) int SSL_library_init(void) { #if defined(AST_DEVMODE) @@ -114,9 +114,6 @@ void ERR_free_strings(void) { /* we can't allow this to be called, ever */ } -#endif /* !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L */ - -#endif /* HAVE_OPENSSL */ /*! * \internal @@ -126,8 +123,6 @@ void ERR_free_strings(void) */ int ast_ssl_init(void) { -#if defined(HAVE_OPENSSL) && defined(OPENSSL_VERSION_NUMBER) && \ - (OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)) unsigned int i; int (*real_SSL_library_init)(void); void (*real_CRYPTO_set_id_callback)(unsigned long (*)(void)); @@ -192,7 +187,14 @@ int ast_ssl_init(void) startup_complete = 1; -#endif /* HAVE_OPENSSL and its version < 1.1 */ return 0; } +#else + +int ast_ssl_init(void) +{ + return 0; +} + +#endif diff --git a/main/manager.c b/main/manager.c index 1bbd1bbe9..d16a69278 100644 --- a/main/manager.c +++ b/main/manager.c @@ -6115,7 +6115,7 @@ static int action_coreshowchannels(struct mansession *s, const struct message *m for (; (msg = ao2_iterator_next(&it_chans)); ao2_ref(msg, -1)) { struct ast_channel_snapshot *cs = stasis_message_data(msg); struct ast_str *built = ast_manager_build_channel_state_string_prefix(cs, ""); - char durbuf[10] = ""; + char durbuf[16] = ""; if (!built) { continue; diff --git a/main/stdtime/localtime.c b/main/stdtime/localtime.c index bb221aebf..88b802028 100644 --- a/main/stdtime/localtime.c +++ b/main/stdtime/localtime.c @@ -2434,7 +2434,7 @@ static const char *store_by_locale(locale_t prevlocale) cur = NULL; AST_LIST_LOCK(&localelist); for (x = 0; x < 10000; x++) { - char name[5]; + char name[6]; snprintf(name, sizeof(name), "%04d", x); if (!find_by_name(name)) { if ((cur = ast_calloc(1, sizeof(*cur) + strlen(name) + 1))) { diff --git a/main/utils.c b/main/utils.c index c254db520..f20ccd36e 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1490,7 +1490,7 @@ char *ast_strsep(char **iss, const char sep, uint32_t flags) int found = 0; char stack[8]; - if (iss == NULL || *iss == '\0') { + if (ast_strlen_zero(st)) { return NULL; } -- cgit v1.2.3