From b02bc230af68d05df171a0a099d6c3d94168ab64 Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Tue, 18 Mar 2008 15:43:34 +0000 Subject: Go through and fix a bunch of places where character strings were being interpreted as format strings. Most of these changes are solely to make compiling with -Wsecurity and -Wformat=2 happy, and were not actual problems, per se. I also added format attributes to any printf wrapper functions I found that didn't have them. -Wsecurity and -Wmissing-format-attribute added to --enable-dev-mode. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109447 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/asterisk.c | 42 +++++++++++++++++++++--------------------- main/cli.c | 2 +- main/features.c | 16 ++++++++-------- main/jitterbuf.c | 2 +- main/manager.c | 18 +++++++++--------- main/translate.c | 2 +- main/utils.c | 4 ++++ 7 files changed, 45 insertions(+), 41 deletions(-) (limited to 'main') diff --git a/main/asterisk.c b/main/asterisk.c index 37cc579cb..9ad011b49 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1374,7 +1374,7 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart) close(ast_consock); if (!ast_opt_remote) unlink(ast_config_AST_PID); - printf(term_quit()); + printf("%s", term_quit()); if (restart) { if (option_verbose || ast_opt_console) ast_verbose("Preparing for Asterisk restart...\n"); @@ -1459,7 +1459,7 @@ static int ast_all_zeros(char *s) static void consolehandler(char *s) { - printf(term_end()); + printf("%s", term_end()); fflush(stdout); /* Called when readline data is available */ @@ -1907,7 +1907,7 @@ static int ast_el_read_char(EditLine *el, char *cp) for (tries = 0; tries < 30 * reconnects_per_second; tries++) { if (ast_tryconnect()) { fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries); - printf(term_quit()); + printf("%s", term_quit()); WELCOME_MESSAGE; if (!ast_opt_mute) fdprint(ast_consock, "logger mute silent"); @@ -3087,7 +3087,7 @@ int main(int argc, char *argv[]) #endif ast_term_init(); - printf(term_end()); + printf("%s", term_end()); fflush(stdout); if (ast_opt_console && !option_verbose) @@ -3112,18 +3112,18 @@ int main(int argc, char *argv[]) quit_handler(0, 0, 0, 0); exit(0); } - printf(term_quit()); + printf("%s", term_quit()); ast_remotecontrol(NULL); quit_handler(0, 0, 0, 0); exit(0); } else { ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET); - printf(term_quit()); + printf("%s", term_quit()); exit(1); } } else if (ast_opt_remote || ast_opt_exec) { ast_log(LOG_ERROR, "Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET); - printf(term_quit()); + printf("%s", term_quit()); exit(1); } /* Blindly write pid file since we couldn't connect */ @@ -3181,7 +3181,7 @@ int main(int argc, char *argv[]) initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool)); if (init_logger()) { /* Start logging subsystem */ - printf(term_quit()); + printf("%s", term_quit()); exit(1); } @@ -3192,12 +3192,12 @@ int main(int argc, char *argv[]) ast_autoservice_init(); if (load_modules(1)) { /* Load modules, pre-load only */ - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (dnsmgr_init()) { /* Initialize the DNS manager */ - printf(term_quit()); + printf("%s", term_quit()); exit(1); } @@ -3206,17 +3206,17 @@ int main(int argc, char *argv[]) ast_channels_init(); if (init_manager()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (ast_cdr_engine_init()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (ast_device_state_engine_init()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } @@ -3225,39 +3225,39 @@ int main(int argc, char *argv[]) ast_udptl_init(); if (ast_image_init()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (ast_file_init()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (load_pbx()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } ast_features_init(); if (init_framer()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (astdb_init()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (ast_enum_init()) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } if (load_modules(0)) { - printf(term_quit()); + printf("%s", term_quit()); exit(1); } @@ -3268,7 +3268,7 @@ int main(int argc, char *argv[]) if (ast_opt_console && !option_verbose) ast_verbose(" ]\n"); if (option_verbose || ast_opt_console) - ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp))); + ast_verbose("%s", term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp))); if (ast_opt_no_fork) consolethread = pthread_self(); diff --git a/main/cli.c b/main/cli.c index 07ad7bcc6..11d6671d8 100644 --- a/main/cli.c +++ b/main/cli.c @@ -878,7 +878,7 @@ static char *handle_commandcomplete(struct ast_cli_entry *e, int cmd, struct ast return CLI_SHOWUSAGE; buf = __ast_cli_generator(a->argv[2], a->argv[3], atoi(a->argv[4]), 0); if (buf) { - ast_cli(a->fd, buf); + ast_cli(a->fd, "%s", buf); ast_free(buf); } else ast_cli(a->fd, "NULL\n"); diff --git a/main/features.c b/main/features.c index 1b6fda4b2..452198540 100644 --- a/main/features.c +++ b/main/features.c @@ -2845,7 +2845,7 @@ static char *handle_feature_show(struct ast_cli_entry *e, int cmd, struct ast_cl { int i; struct ast_call_feature *feature; - char format[] = "%-25s %-7s %-7s\n"; +#define HFS_FORMAT "%-25s %-7s %-7s\n" switch (cmd) { @@ -2859,25 +2859,25 @@ static char *handle_feature_show(struct ast_cli_entry *e, int cmd, struct ast_cl return NULL; } - ast_cli(a->fd, format, "Builtin Feature", "Default", "Current"); - ast_cli(a->fd, format, "---------------", "-------", "-------"); + ast_cli(a->fd, HFS_FORMAT, "Builtin Feature", "Default", "Current"); + ast_cli(a->fd, HFS_FORMAT, "---------------", "-------", "-------"); - ast_cli(a->fd, format, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */ + ast_cli(a->fd, HFS_FORMAT, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */ ast_rwlock_rdlock(&features_lock); for (i = 0; i < FEATURES_COUNT; i++) - ast_cli(a->fd, format, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten); + ast_cli(a->fd, HFS_FORMAT, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten); ast_rwlock_unlock(&features_lock); ast_cli(a->fd, "\n"); - ast_cli(a->fd, format, "Dynamic Feature", "Default", "Current"); - ast_cli(a->fd, format, "---------------", "-------", "-------"); + ast_cli(a->fd, HFS_FORMAT, "Dynamic Feature", "Default", "Current"); + ast_cli(a->fd, HFS_FORMAT, "---------------", "-------", "-------"); if (AST_LIST_EMPTY(&feature_list)) ast_cli(a->fd, "(none)\n"); else { AST_LIST_LOCK(&feature_list); AST_LIST_TRAVERSE(&feature_list, feature, feature_entry) - ast_cli(a->fd, format, feature->sname, "no def", feature->exten); + ast_cli(a->fd, HFS_FORMAT, feature->sname, "no def", feature->exten); AST_LIST_UNLOCK(&feature_list); } ast_cli(a->fd, "\nCall parking\n"); diff --git a/main/jitterbuf.c b/main/jitterbuf.c index a7f3b2cd9..d8297a0a8 100644 --- a/main/jitterbuf.c +++ b/main/jitterbuf.c @@ -560,7 +560,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now, /* if a hard clamp was requested, use it */ if ((jb->info.conf.max_jitterbuf) && ((jb->info.target - jb->info.min) > jb->info.conf.max_jitterbuf)) { - jb_dbg("clamping target from %d to %d\n", (jb->info.target - jb->info.min), jb->info.conf.max_jitterbuf); + jb_dbg("clamping target from %ld to %ld\n", (jb->info.target - jb->info.min), jb->info.conf.max_jitterbuf); jb->info.target = jb->info.min + jb->info.conf.max_jitterbuf; } diff --git a/main/manager.c b/main/manager.c index 1d4ff1857..e205eb012 100644 --- a/main/manager.c +++ b/main/manager.c @@ -644,7 +644,7 @@ static char *handle_showmancmds(struct ast_cli_entry *e, int cmd, struct ast_cli { struct manager_action *cur; struct ast_str *authority; - static const char *format = " %-15.15s %-15.15s %-55.55s\n"; +#define HSMC_FORMAT " %-15.15s %-15.15s %-55.55s\n" switch (cmd) { case CLI_INIT: e->command = "manager show commands"; @@ -656,12 +656,12 @@ static char *handle_showmancmds(struct ast_cli_entry *e, int cmd, struct ast_cli return NULL; } authority = ast_str_alloca(80); - ast_cli(a->fd, format, "Action", "Privilege", "Synopsis"); - ast_cli(a->fd, format, "------", "---------", "--------"); + ast_cli(a->fd, HSMC_FORMAT, "Action", "Privilege", "Synopsis"); + ast_cli(a->fd, HSMC_FORMAT, "------", "---------", "--------"); AST_RWLIST_RDLOCK(&actions); AST_RWLIST_TRAVERSE(&actions, cur, list) - ast_cli(a->fd, format, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis); + ast_cli(a->fd, HSMC_FORMAT, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis); AST_RWLIST_UNLOCK(&actions); return CLI_SUCCESS; @@ -672,8 +672,8 @@ static char *handle_showmanconn(struct ast_cli_entry *e, int cmd, struct ast_cli { struct mansession *s; time_t now = time(NULL); - static const char *format = " %-15.15s %-15.15s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n"; - static const char *format2 = " %-15.15s %-15.15s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n"; +#define HSMCONN_FORMAT1 " %-15.15s %-15.15s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n" +#define HSMCONN_FORMAT2 " %-15.15s %-15.15s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n" int count = 0; switch (cmd) { case CLI_INIT: @@ -687,11 +687,11 @@ static char *handle_showmanconn(struct ast_cli_entry *e, int cmd, struct ast_cli return NULL; } - ast_cli(a->fd, format, "Username", "IP Address", "Start", "Elapsed", "FileDes", "HttpCnt", "Read", "Write"); + ast_cli(a->fd, HSMCONN_FORMAT1, "Username", "IP Address", "Start", "Elapsed", "FileDes", "HttpCnt", "Read", "Write"); AST_LIST_LOCK(&sessions); AST_LIST_TRAVERSE(&sessions, s, list) { - ast_cli(a->fd, format2, s->username, ast_inet_ntoa(s->sin.sin_addr), (int)(s->sessionstart), (int)(now - s->sessionstart), s->fd, s->inuse, s->readperm, s->writeperm); + ast_cli(a->fd, HSMCONN_FORMAT2, s->username, ast_inet_ntoa(s->sin.sin_addr), (int)(s->sessionstart), (int)(now - s->sessionstart), s->fd, s->inuse, s->readperm, s->writeperm); count++; } AST_LIST_UNLOCK(&sessions); @@ -3589,7 +3589,7 @@ static struct ast_str *generic_http_callback(enum output_format format, if (format == FORMAT_XML || format == FORMAT_HTML) xml_translate(&out, buf, params, format); else - ast_str_append(&out, 0, buf); + ast_str_append(&out, 0, "%s", buf); munmap(buf, l); } } else if (format == FORMAT_XML || format == FORMAT_HTML) { diff --git a/main/translate.c b/main/translate.c index be10b11b2..750b2f5b6 100644 --- a/main/translate.c +++ b/main/translate.c @@ -592,7 +592,7 @@ static char *handle_cli_core_show_translation(struct ast_cli_entry *e, int cmd, } } ast_str_append(&out, -1, "\n"); - ast_cli(a->fd, out->str); + ast_cli(a->fd, "%s", out->str); } AST_RWLIST_UNLOCK(&translators); return CLI_SUCCESS; diff --git a/main/utils.c b/main/utils.c index c3edcd626..b4a7d3279 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1349,6 +1349,7 @@ ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr return result; } +__attribute((format (printf, 4, 0))) void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, const ast_string_field *ptr, const char *format, va_list ap1, va_list ap2) @@ -1380,6 +1381,7 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, mgr->used += needed; } +__attribute((format (printf, 4, 5))) void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, const ast_string_field *ptr, const char *format, ...) @@ -1470,6 +1472,8 @@ int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed) * ast_str_set_va(...) * ast_str_append_va(...) */ + +__attribute__((format (printf, 4, 0))) int __ast_str_helper(struct ast_str **buf, size_t max_len, int append, const char *fmt, va_list ap) { -- cgit v1.2.3