From 749029de38e8b8c02172912917e2642b8c96547c Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Wed, 25 Oct 2006 14:44:50 +0000 Subject: Merged revisions 46200 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r46200 | kpfleming | 2006-10-25 09:32:08 -0500 (Wed, 25 Oct 2006) | 2 lines apparently developers are still not aware that they should be use ast_copy_string instead of strncpy... fix up many more users, and fix some bugs in the process ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@46201 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_getcpeid.c | 39 +++++++++++++++++++-------------------- apps/app_ices.c | 2 +- apps/app_parkandannounce.c | 22 +++++----------------- apps/app_queue.c | 26 +++++++++----------------- apps/app_record.c | 2 +- apps/app_sms.c | 2 +- apps/app_softhangup.c | 2 +- apps/app_voicemail.c | 38 ++++++++++++++++++-------------------- 8 files changed, 55 insertions(+), 78 deletions(-) (limited to 'apps') diff --git a/apps/app_getcpeid.c b/apps/app_getcpeid.c index f0e39e036..f0c5d1b07 100644 --- a/apps/app_getcpeid.c +++ b/apps/app_getcpeid.c @@ -71,21 +71,20 @@ static int cpeid_exec(struct ast_channel *chan, void *idata) int gotgeometry = 0; int gotcpeid = 0; int width, height, buttons; - char data[4][80]; - char *stuff[4]; + char *data[4]; + unsigned int x; u = ast_module_user_add(chan); - stuff[0] = data[0]; - stuff[1] = data[1]; - stuff[2] = data[2]; - stuff[3] = data[3]; - memset(data, 0, sizeof(data)); - strncpy(stuff[0], "** CPE Info **", sizeof(data[0]) - 1); - strncpy(stuff[1], "Identifying CPE...", sizeof(data[1]) - 1); - strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1); + + for (x = 0; x < 4; x++) + data[x] = alloca(80); + + strcpy(data[0], "** CPE Info **"); + strcpy(data[1], "Identifying CPE..."); + strcpy(data[2], "Please wait..."); res = ast_adsi_load_session(chan, NULL, 0, 1); if (res > 0) { - cpeid_setstatus(chan, stuff, 0); + cpeid_setstatus(chan, data, 0); res = ast_adsi_get_cpeid(chan, cpeid, 0); if (res > 0) { gotcpeid = 1; @@ -93,9 +92,9 @@ static int cpeid_exec(struct ast_channel *chan, void *idata) ast_verbose(VERBOSE_PREFIX_3 "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name); } if (res > -1) { - strncpy(stuff[1], "Measuring CPE...", sizeof(data[1]) - 1); - strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1); - cpeid_setstatus(chan, stuff, 0); + strcpy(data[1], "Measuring CPE..."); + strcpy(data[2], "Please wait..."); + cpeid_setstatus(chan, data, 0); res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0); if (res > -1) { if (option_verbose > 2) @@ -105,15 +104,15 @@ static int cpeid_exec(struct ast_channel *chan, void *idata) } if (res > -1) { if (gotcpeid) - snprintf(stuff[1], sizeof(data[1]), "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]); + snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]); else - strncpy(stuff[1], "CPEID Unknown", sizeof(data[1]) - 1); + strcpy(data[1], "CPEID Unknown"); if (gotgeometry) - snprintf(stuff[2], sizeof(data[2]), "Geom: %dx%d, %d buttons", width, height, buttons); + snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons); else - strncpy(stuff[2], "Geometry unknown", sizeof(data[2]) - 1); - strncpy(stuff[3], "Press # to exit", sizeof(data[3]) - 1); - cpeid_setstatus(chan, stuff, 1); + strcpy(data[2], "Geometry unknown"); + strcpy(data[3], "Press # to exit"); + cpeid_setstatus(chan, data, 1); for(;;) { res = ast_waitfordigit(chan, 1000); if (res < 0) diff --git a/apps/app_ices.c b/apps/app_ices.c index 4a223bd5d..869254738 100644 --- a/apps/app_ices.c +++ b/apps/app_ices.c @@ -141,7 +141,7 @@ static int ices_exec(struct ast_channel *chan, void *data) return -1; } if (((char *)data)[0] == '/') - strncpy(filename, (char *)data, sizeof(filename) - 1); + ast_copy_string(filename, (char *) data, sizeof(filename)); else snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, (char *)data); /* Placeholder for options */ diff --git a/apps/app_parkandannounce.c b/apps/app_parkandannounce.c index 66203b1b0..b4e9006fb 100644 --- a/apps/app_parkandannounce.c +++ b/apps/app_parkandannounce.c @@ -78,13 +78,13 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) { int res=0; char *return_context; - int l, lot, timeout = 0, dres; + int lot, timeout = 0, dres; char *working, *context, *exten, *priority, *dial, *dialtech, *dialstr; char *template, *tpl_working, *tpl_current; char *tmp[100]; char buf[13]; int looptemp=0,i=0; - char *s,*orig_s; + char *s; struct ast_channel *dchan; struct outgoing_helper oh; @@ -99,18 +99,11 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) u = ast_module_user_add(chan); - l=strlen(data)+2; - if (!(orig_s = ast_malloc(l))) { - ast_module_user_remove(u); - return -1; - } - s=orig_s; - strncpy(s,data,l); + s = ast_strdupa(data); template=strsep(&s,"|"); if(! template) { ast_log(LOG_WARNING, "PARK: An announce template must be defined\n"); - free(orig_s); ast_module_user_remove(u); return -1; } @@ -122,7 +115,6 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) dial=strsep(&s, "|"); if(!dial) { ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or Zap/g1/5551212\n"); - free(orig_s); ast_module_user_remove(u); return -1; } else { @@ -155,16 +147,15 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) } if(atoi(priority) < 0) { ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority); - free(orig_s); ast_module_user_remove(u); return -1; } /* At this point we have a priority and maybe an extension and a context */ chan->priority = atoi(priority); if (exten) - strncpy(chan->exten, exten, sizeof(chan->exten)-1); + ast_copy_string(chan->exten, exten, sizeof(chan->exten)); if (context) - strncpy(chan->context, context, sizeof(chan->context)-1); + ast_copy_string(chan->context, context, sizeof(chan->context)); } else { /* increment the priority by default*/ chan->priority++; } @@ -202,13 +193,11 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", dchan->name); ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name); ast_hangup(dchan); - free(orig_s); ast_module_user_remove(u); return -1; } } else { ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n"); - free(orig_s); ast_module_user_remove(u); return -1; } @@ -245,7 +234,6 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) ast_stopstream(dchan); ast_hangup(dchan); - free(orig_s); ast_module_user_remove(u); diff --git a/apps/app_queue.c b/apps/app_queue.c index f0dbe883e..ebbf76ae2 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -767,10 +767,6 @@ static void clear_and_free_interfaces(void) extra fields in the tables. */ static void queue_set_param(struct call_queue *q, const char *param, const char *val, int linenum, int failunknown) { - int i = 0; - char *c, *lastc; - char buff[80]; - if (!strcasecmp(param, "musicclass") || !strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) { ast_copy_string(q->moh, val, sizeof(q->moh)); @@ -831,22 +827,18 @@ static void queue_set_param(struct call_queue *q, const char *param, const char else q->announceholdtime = 0; } else if (!strcasecmp(param, "periodic-announce")) { - if (strchr(val,'|')) { - lastc = (char *)val; - while ((c = strchr(lastc,'|'))) { - if (i > MAX_PERIODIC_ANNOUNCEMENTS) - break; - strncpy(buff, lastc, abs(lastc - c)); - buff[abs(lastc - c)] = '\0'; - ast_copy_string(q->sound_periodicannounce[i], buff, sizeof(q->sound_periodicannounce[i])); - lastc = (c + 1); + if (strchr(val, '|')) { + char *s, *buf = ast_strdupa(val); + unsigned int i = 0; + + while ((s = strsep(&buf, "|"))) { + ast_copy_string(q->sound_periodicannounce[i], s, sizeof(q->sound_periodicannounce[i])); i++; - } - if (strlen(lastc)) { - ast_copy_string(q->sound_periodicannounce[i], lastc, sizeof(q->sound_periodicannounce[i])); + if (i == MAX_PERIODIC_ANNOUNCEMENTS) + break; } } else { - ast_copy_string(q->sound_periodicannounce[i], val, sizeof(q->sound_periodicannounce[i])); + ast_copy_string(q->sound_periodicannounce[0], val, sizeof(q->sound_periodicannounce[0])); } } else if (!strcasecmp(param, "periodic-announce-frequency")) { q->periodicannouncefrequency = atoi(val); diff --git a/apps/app_record.c b/apps/app_record.c index 924e6ba2d..b38944aef 100644 --- a/apps/app_record.c +++ b/apps/app_record.c @@ -212,7 +212,7 @@ static int record_exec(struct ast_channel *chan, void *data) } while (ast_fileexists(tmp, ext, chan->language) > 0); pbx_builtin_setvar_helper(chan, "RECORDED_FILE", tmp); } else - strncpy(tmp, filename, sizeof(tmp)-1); + ast_copy_string(tmp, filename, sizeof(tmp)); /* end of routine mentioned */ diff --git a/apps/app_sms.c b/apps/app_sms.c index 8fd5ee617..5bb076e81 100644 --- a/apps/app_sms.c +++ b/apps/app_sms.c @@ -1389,7 +1389,7 @@ static int sms_exec (struct ast_channel *chan, void *data) ast_module_user_remove(u); return -1; } - strncpy (h.queue, (char *)d, p - d); + strncpy(h.queue, (char *)d, p - d); if (*p == '|') p++; d = p; diff --git a/apps/app_softhangup.c b/apps/app_softhangup.c index 46584c3e7..018edc07d 100644 --- a/apps/app_softhangup.c +++ b/apps/app_softhangup.c @@ -74,7 +74,7 @@ static int softhangup_exec(struct ast_channel *chan, void *data) all = options && strchr(options,'a'); c = ast_channel_walk_locked(NULL); while (c) { - strncpy(name, c->name, sizeof(name)-1); + ast_copy_string(name, c->name, sizeof(name)); ast_mutex_unlock(&c->lock); /* XXX watch out, i think it is wrong to access c-> after unlocking! */ if (all) { diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index e2b8f2ed3..476cc2b34 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -7278,23 +7278,22 @@ static int load_config(void) char *tmpread, *tmpwrite; emailbody = ast_strdup(s); - /* substitute strings \t and \n into the apropriate characters */ + /* substitute strings \t and \n into the appropriate characters */ tmpread = tmpwrite = emailbody; while ((tmpwrite = strchr(tmpread,'\\'))) { - int len = strlen("\n"); switch (tmpwrite[1]) { case 'n': - strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1); - strncpy(tmpwrite, "\n", len); + *tmpwrite++ = '\n'; + memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1); break; case 't': - strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1); - strncpy(tmpwrite, "\t", len); + *tmpwrite++ = '\t'; + memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1); break; default: ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n", tmpwrite[1]); } - tmpread = tmpwrite + len; + tmpread = tmpwrite + 1; } } if ((s = ast_variable_retrieve(cfg, "general", "pagersubject"))) @@ -7303,23 +7302,22 @@ static int load_config(void) char *tmpread, *tmpwrite; pagerbody = ast_strdup(s); - /* substitute strings \t and \n into the apropriate characters */ + /* substitute strings \t and \n into the appropriate characters */ tmpread = tmpwrite = pagerbody; while ((tmpwrite = strchr(tmpread, '\\'))) { - int len = strlen("\n"); switch (tmpwrite[1]) { - case 'n': - strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1); - strncpy(tmpwrite, "\n", len); - break; - case 't': - strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1); - strncpy(tmpwrite, "\t", len); - break; - default: - ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n", tmpwrite[1]); + case 'n': + *tmpwrite++ = '\n'; + memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1); + break; + case 't': + *tmpwrite++ = '\t'; + memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1); + break; + default: + ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n", tmpwrite[1]); } - tmpread = tmpwrite + len; + tmpread = tmpwrite + 1; } } AST_LIST_UNLOCK(&users); -- cgit v1.2.3