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 --- apps/app_festival.c | 24 ++++++++++++++++++------ apps/app_meetme.c | 8 ++++---- apps/app_minivm.c | 28 ++++++++++++++-------------- apps/app_queue.c | 4 ++-- apps/app_voicemail.c | 24 ++++++++---------------- 5 files changed, 46 insertions(+), 42 deletions(-) (limited to 'apps') diff --git a/apps/app_festival.c b/apps/app_festival.c index 926638e57..e788291ed 100644 --- a/apps/app_festival.c +++ b/apps/app_festival.c @@ -327,11 +327,21 @@ static int festival_exec(struct ast_channel *chan, void *vdata) if (!(cachedir = ast_variable_retrieve(cfg, "general", "cachedir"))) { cachedir = "/tmp/"; } + + data = ast_strdupa(vdata); + AST_STANDARD_APP_ARGS(args, data); + if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) { - festivalcommand = "(tts_textasterisk \"%s\" 'file)(quit)\n"; + const char *startcmd = "(tts_textasterisk \""; + const char *endcmd = "\" 'file)(quit)\n"; + + strln = strlen(startcmd) + strlen(args.text) + strlen(endcmd) + 1; + newfestivalcommand = alloca(strln); + snprintf(newfestivalcommand, strln, "%s%s%s", startcmd, args.text, endcmd); + festivalcommand = newfestivalcommand; } else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */ int i, j; - newfestivalcommand = alloca(strlen(festivalcommand) + 1); + newfestivalcommand = alloca(strlen(festivalcommand) + strlen(args.text) + 1); for (i = 0, j = 0; i < strlen(festivalcommand); i++) { if (festivalcommand[i] == '\\' && festivalcommand[i + 1] == 'n') { @@ -340,6 +350,10 @@ static int festival_exec(struct ast_channel *chan, void *vdata) } else if (festivalcommand[i] == '\\') { newfestivalcommand[j++] = festivalcommand[i + 1]; i++; + } else if (festivalcommand[i] == '%' && festivalcommand[i + 1] == 's') { + sprintf(&newfestivalcommand[j], "%s", args.text); /* we know it is big enough */ + j += strlen(args.text); + i++; } else newfestivalcommand[j++] = festivalcommand[i]; } @@ -347,9 +361,6 @@ static int festival_exec(struct ast_channel *chan, void *vdata) festivalcommand = newfestivalcommand; } - data = ast_strdupa(vdata); - AST_STANDARD_APP_ARGS(args, data); - if (args.interrupt && !strcasecmp(args.interrupt, "any")) args.interrupt = AST_DIGIT_ANY; @@ -440,7 +451,8 @@ static int festival_exec(struct ast_channel *chan, void *vdata) } else { ast_debug(1, "Passing text to festival...\n"); fs = fdopen(dup(fd), "wb"); - fprintf(fs, festivalcommand, args.text); + + fprintf(fs, "%s", festivalcommand); fflush(fs); fclose(fs); } diff --git a/apps/app_meetme.c b/apps/app_meetme.c index f89e51ab0..bda9050c8 100644 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -955,9 +955,9 @@ static char *meetme_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a int hr, min, sec; int i = 0, total = 0; time_t now; - char *header_format = "%-14s %-14s %-10s %-8s %-8s %-6s\n"; - char *data_format = "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s %-6s\n"; char cmdline[1024] = ""; +#define MC_HEADER_FORMAT "%-14s %-14s %-10s %-8s %-8s %-6s\n" +#define MC_DATA_FORMAT "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s %-6s\n" switch (cmd) { case CLI_INIT: @@ -989,7 +989,7 @@ static char *meetme_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a return CLI_SUCCESS; } if (!concise) - ast_cli(a->fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked"); + ast_cli(a->fd, MC_HEADER_FORMAT, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked"); AST_LIST_TRAVERSE(&confs, cnf, list) { if (cnf->markedusers == 0) strcpy(cmdline, "N/A "); @@ -999,7 +999,7 @@ static char *meetme_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a min = ((now - cnf->start) % 3600) / 60; sec = (now - cnf->start) % 60; if (!concise) - ast_cli(a->fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No"); + ast_cli(a->fd, MC_DATA_FORMAT, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No"); else { ast_cli(a->fd, "%s!%d!%d!%02d:%02d:%02d!%d!%d\n", cnf->confno, diff --git a/apps/app_minivm.c b/apps/app_minivm.c index f11537ed0..1ac2576fe 100644 --- a/apps/app_minivm.c +++ b/apps/app_minivm.c @@ -1560,10 +1560,10 @@ static int leave_voicemail(struct ast_channel *chan, char *username, struct leav duration < global_vmminmessage ? "IGNORED" : "OK", vmu->accountcode ); - fprintf(txt, logbuf); + fprintf(txt, "%s", logbuf); if (minivmlogfile) { ast_mutex_lock(&minivmloglock); - fprintf(minivmlogfile, logbuf); + fprintf(minivmlogfile, "%s", logbuf); ast_mutex_unlock(&minivmloglock); } @@ -2475,7 +2475,7 @@ static int load_config(int reload) static char *handle_minivm_list_templates(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct minivm_template *this; - char *output_format = "%-15s %-10s %-10s %-15.15s %-50s\n"; +#define HVLT_OUTPUT_FORMAT "%-15s %-10s %-10s %-15.15s %-50s\n" int count = 0; switch (cmd) { @@ -2498,10 +2498,10 @@ static char *handle_minivm_list_templates(struct ast_cli_entry *e, int cmd, stru AST_LIST_UNLOCK(&message_templates); return CLI_FAILURE; } - ast_cli(a->fd, output_format, "Template name", "Charset", "Locale", "Attach media", "Subject"); - ast_cli(a->fd, output_format, "-------------", "-------", "------", "------------", "-------"); + ast_cli(a->fd, HVLT_OUTPUT_FORMAT, "Template name", "Charset", "Locale", "Attach media", "Subject"); + ast_cli(a->fd, HVLT_OUTPUT_FORMAT, "-------------", "-------", "------", "------------", "-------"); AST_LIST_TRAVERSE(&message_templates, this, list) { - ast_cli(a->fd, output_format, this->name, + ast_cli(a->fd, HVLT_OUTPUT_FORMAT, this->name, this->charset ? this->charset : "-", this->locale ? this->locale : "-", this->attachment ? "Yes" : "No", @@ -2541,7 +2541,7 @@ static char *complete_minivm_show_users(const char *line, const char *word, int static char *handle_minivm_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct minivm_account *vmu; - char *output_format = "%-23s %-15s %-15s %-10s %-10s %-50s\n"; +#define HMSU_OUTPUT_FORMAT "%-23s %-15s %-15s %-10s %-10s %-50s\n" int count = 0; switch (cmd) { @@ -2566,14 +2566,14 @@ static char *handle_minivm_show_users(struct ast_cli_entry *e, int cmd, struct a AST_LIST_UNLOCK(&minivm_accounts); return CLI_FAILURE; } - ast_cli(a->fd, output_format, "User", "E-Template", "P-template", "Zone", "Format", "Full name"); - ast_cli(a->fd, output_format, "----", "----------", "----------", "----", "------", "---------"); + ast_cli(a->fd, HMSU_OUTPUT_FORMAT, "User", "E-Template", "P-template", "Zone", "Format", "Full name"); + ast_cli(a->fd, HMSU_OUTPUT_FORMAT, "----", "----------", "----------", "----", "------", "---------"); AST_LIST_TRAVERSE(&minivm_accounts, vmu, list) { char tmp[256] = ""; if ((a->argc == 3) || ((a->argc == 5) && !strcmp(a->argv[4], vmu->domain))) { count++; snprintf(tmp, sizeof(tmp), "%s@%s", vmu->username, vmu->domain); - ast_cli(a->fd, output_format, tmp, vmu->etemplate ? vmu->etemplate : "-", + ast_cli(a->fd, HMSU_OUTPUT_FORMAT, tmp, vmu->etemplate ? vmu->etemplate : "-", vmu->ptemplate ? vmu->ptemplate : "-", vmu->zonetag ? vmu->zonetag : "-", vmu->attachfmt ? vmu->attachfmt : "-", @@ -2589,7 +2589,7 @@ static char *handle_minivm_show_users(struct ast_cli_entry *e, int cmd, struct a static char *handle_minivm_show_zones(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct minivm_zone *zone; - char *output_format = "%-15s %-20s %-45s\n"; +#define HMSZ_OUTPUT_FORMAT "%-15s %-20s %-45s\n" char *res = CLI_SUCCESS; switch (cmd) { @@ -2608,10 +2608,10 @@ static char *handle_minivm_show_zones(struct ast_cli_entry *e, int cmd, struct a AST_LIST_LOCK(&minivm_zones); if (!AST_LIST_EMPTY(&minivm_zones)) { - ast_cli(a->fd, output_format, "Zone", "Timezone", "Message Format"); - ast_cli(a->fd, output_format, "----", "--------", "--------------"); + ast_cli(a->fd, HMSZ_OUTPUT_FORMAT, "Zone", "Timezone", "Message Format"); + ast_cli(a->fd, HMSZ_OUTPUT_FORMAT, "----", "--------", "--------------"); AST_LIST_TRAVERSE(&minivm_zones, zone, list) { - ast_cli(a->fd, output_format, zone->name, zone->timezone, zone->msg_format); + ast_cli(a->fd, HMSZ_OUTPUT_FORMAT, zone->name, zone->timezone, zone->msg_format); } } else { ast_cli(a->fd, "There are no voicemail zones currently defined\n"); diff --git a/apps/app_queue.c b/apps/app_queue.c index a1dadb0d3..b034b9e3a 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -1232,13 +1232,13 @@ static void queue_set_param(struct call_queue *q, const char *param, const char while ((s = strsep(&buf, ",|"))) { if (!q->sound_periodicannounce[i]) q->sound_periodicannounce[i] = ast_str_create(16); - ast_str_set(&q->sound_periodicannounce[i], 0, s); + ast_str_set(&q->sound_periodicannounce[i], 0, "%s", s); i++; if (i == MAX_PERIODIC_ANNOUNCEMENTS) break; } } else { - ast_str_set(&q->sound_periodicannounce[0], 0, val); + ast_str_set(&q->sound_periodicannounce[0], 0, "%s", val); } } else if (!strcasecmp(param, "periodic-announce-frequency")) { q->periodicannouncefrequency = atoi(val); diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 8042ea6f2..c82047f35 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -645,7 +645,6 @@ static char *pagerbody = NULL; static char *pagersubject = NULL; static char fromstring[100]; static char pagerfromstring[100]; -static char emailtitle[100]; static char charset[32] = "ISO-8859-1"; static unsigned char adsifdn[4] = "\x00\x00\x00\x0F"; @@ -2021,9 +2020,6 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in ast_channel_free(ast); } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); - } else if (!ast_strlen_zero(emailtitle)) { - fprintf(p, emailtitle, msgnum + 1, mailbox) ; - fprintf(p, ENDL) ; } else if (ast_test_flag((&globalflags), VM_PBXSKIP)) fprintf(p, "Subject: New message %d in mailbox %s" ENDL, msgnum + 1, mailbox); else @@ -7802,7 +7798,7 @@ static char *complete_voicemail_show_users(const char *line, const char *word, i static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_vm_user *vmu; - char *output_format = "%-10s %-5s %-25s %-10s %6s\n"; +#define HVSU_OUTPUT_FORMAT "%-10s %-5s %-25s %-10s %6s\n" const char *context = NULL; int users_counter = 0; @@ -7840,7 +7836,7 @@ static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struc return CLI_FAILURE; } if (a->argc == 3) - ast_cli(a->fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg"); + ast_cli(a->fd, HVSU_OUTPUT_FORMAT, "Context", "Mbox", "User", "Zone", "NewMsg"); else { int count = 0; AST_LIST_TRAVERSE(&users, vmu, list) { @@ -7848,7 +7844,7 @@ static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struc count++; } if (count) { - ast_cli(a->fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg"); + ast_cli(a->fd, HVSU_OUTPUT_FORMAT, "Context", "Mbox", "User", "Zone", "NewMsg"); } else { ast_cli(a->fd, "No such voicemail context \"%s\"\n", context); AST_LIST_UNLOCK(&users); @@ -7863,7 +7859,7 @@ static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struc snprintf(tmp, sizeof(tmp), "%s@%s", vmu->mailbox, ast_strlen_zero(vmu->context) ? "default" : vmu->context); inboxcount(tmp, &newmsgs, &oldmsgs); snprintf(count, sizeof(count), "%d", newmsgs); - ast_cli(a->fd, output_format, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count); + ast_cli(a->fd, HVSU_OUTPUT_FORMAT, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count); users_counter++; } } @@ -7876,7 +7872,7 @@ static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struc static char *handle_voicemail_show_zones(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct vm_zone *zone; - char *output_format = "%-15s %-20s %-45s\n"; +#define HVSZ_OUTPUT_FORMAT "%-15s %-20s %-45s\n" char *res = CLI_SUCCESS; switch (cmd) { @@ -7895,9 +7891,9 @@ static char *handle_voicemail_show_zones(struct ast_cli_entry *e, int cmd, struc AST_LIST_LOCK(&zones); if (!AST_LIST_EMPTY(&zones)) { - ast_cli(a->fd, output_format, "Zone", "Timezone", "Message Format"); + ast_cli(a->fd, HVSZ_OUTPUT_FORMAT, "Zone", "Timezone", "Message Format"); AST_LIST_TRAVERSE(&zones, zone, list) { - ast_cli(a->fd, output_format, zone->name, zone->timezone, zone->msg_format); + ast_cli(a->fd, HVSZ_OUTPUT_FORMAT, zone->name, zone->timezone, zone->msg_format); } } else { ast_cli(a->fd, "There are no voicemail zones currently defined\n"); @@ -8720,7 +8716,6 @@ static int load_config(int reload) } memset(fromstring, 0, sizeof(fromstring)); memset(pagerfromstring, 0, sizeof(pagerfromstring)); - memset(emailtitle, 0, sizeof(emailtitle)); strcpy(charset, "ISO-8859-1"); if (emailbody) { ast_free(emailbody); @@ -8758,13 +8753,10 @@ static int load_config(int reload) memcpy(&adsisec[x], &tmpadsi[x], 1); } } - if ((val = ast_variable_retrieve(cfg, "general", "adsiver"))) + if ((val = ast_variable_retrieve(cfg, "general", "adsiver"))) { if (atoi(val)) { adsiver = atoi(val); } - if ((val = ast_variable_retrieve(cfg, "general", "emailtitle"))) { - ast_log(LOG_NOTICE, "Keyword 'emailtitle' is DEPRECATED, please use 'emailsubject' instead.\n"); - ast_copy_string(emailtitle, val, sizeof(emailtitle)); } if ((val = ast_variable_retrieve(cfg, "general", "emailsubject"))) emailsubject = ast_strdup(val); -- cgit v1.2.3