Convert some strncpys to ast_copy_string
authorTerry Wilson <twilson@digium.com>
Thu, 19 Apr 2012 19:05:17 +0000 (19:05 +0000)
committerTerry Wilson <twilson@digium.com>
Thu, 19 Apr 2012 19:05:17 +0000 (19:05 +0000)
Review: https://reviewboard.asterisk.org/r/1732/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@362635 65c4cc65-6c06-0410-ace0-fbb531ad65f3

addons/chan_ooh323.c
apps/app_alarmreceiver.c
channels/iax2-provision.c
res/snmp/agent.c

index c395d90..bf3991f 100644 (file)
@@ -1800,7 +1800,7 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
 
        number[0] = '\0';
        if(ooCallGetCalledPartyNumber(call, number, OO_MAX_NUMBER_LENGTH)== OO_OK) {
-               strncpy(p->exten, number, sizeof(p->exten)-1);
+               ast_copy_string(p->exten, number, sizeof(p->exten));
        } else {
                update_our_aliases(call, p);
                if (!ast_strlen_zero(p->callee_dialedDigits)) {
@@ -2296,8 +2296,7 @@ static struct ooh323_user *build_user(const char *name, struct ast_variable *v)
                                if (user->incominglimit < 0)
                                        user->incominglimit = 0;
                        } else if (!strcasecmp(v->name, "accountcode")) {
-                               strncpy(user->accountcode, v->value, 
-                                               sizeof(user->accountcode)-1);
+                               ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
                        } else if (!strcasecmp(v->name, "roundtrip")) {
                                sscanf(v->value, "%d,%d", &user->rtdrcount, &user->rtdrinterval);
                        } else if (!strcasecmp(v->name, "faststart")) {
@@ -2832,12 +2831,12 @@ int reload_config(int reload)
                                gRasGkMode = RasDiscoverGatekeeper;
                        } else {
                                gRasGkMode = RasUseSpecificGatekeeper;
-                               strncpy(gGatekeeper, v->value, sizeof(gGatekeeper)-1);
+                               ast_copy_string(gGatekeeper, v->value, sizeof(gGatekeeper));
                        }
                } else if (!strcasecmp(v->name, "logfile")) {
-                       strncpy(gLogFile, v->value, sizeof(gLogFile)-1);
+                       ast_copy_string(gLogFile, v->value, sizeof(gLogFile));
                } else if (!strcasecmp(v->name, "context")) {
-                       strncpy(gContext, v->value, sizeof(gContext)-1);
+                       ast_copy_string(gContext, v->value, sizeof(gContext));
                        ast_verb(3, "  == Setting default context to %s\n", gContext);
                } else if (!strcasecmp(v->name, "nat")) {
                        gNat = ast_true(v->value);
@@ -4307,7 +4306,7 @@ int configure_local_rtp(struct ooh323_pvt *p, ooCallData *call)
                }
                /* figure out our local RTP port and tell the H.323 stack about it*/
                ast_rtp_instance_get_local_address(p->rtp, &tmp);
-               strncpy(lhost, ast_sockaddr_stringify_addr(&tmp), sizeof(lhost));
+               ast_copy_string(lhost, ast_sockaddr_stringify_addr(&tmp), sizeof(lhost));
                lport = ast_sockaddr_stringify_port(&tmp);
 
                if (p->rtptimeout) {
@@ -4351,7 +4350,7 @@ int configure_local_rtp(struct ooh323_pvt *p, ooCallData *call)
 
        if (p->udptl) {
                ast_udptl_get_us(p->udptl, &tmp);
-               strncpy(lhost, ast_sockaddr_stringify_addr(&tmp), sizeof(lhost));
+               ast_copy_string(lhost, ast_sockaddr_stringify_addr(&tmp), sizeof(lhost));
                lport = ast_sockaddr_stringify_port(&tmp);
                ast_copy_string(mediaInfo.lMediaIP, lhost, sizeof(mediaInfo.lMediaIP));
                mediaInfo.lMediaPort = atoi(lport);
index 574a59d..53dac30 100644 (file)
@@ -663,7 +663,6 @@ static int load_config(void)
                p = ast_variable_retrieve(cfg, "general", "eventcmd");
                if (p) {
                        ast_copy_string(event_app, p, sizeof(event_app));
-                       event_app[sizeof(event_app) - 1] = '\0';
                }
                p = ast_variable_retrieve(cfg, "general", "loudness");
                if (p) {
@@ -698,19 +697,16 @@ static int load_config(void)
                p = ast_variable_retrieve(cfg, "general", "eventspooldir");
                if (p) {
                        ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir));
-                       event_spool_dir[sizeof(event_spool_dir) - 1] = '\0';
                }
 
                p = ast_variable_retrieve(cfg, "general", "timestampformat");
                if (p) {
                        ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format));
-                       time_stamp_format[sizeof(time_stamp_format) - 1] = '\0';
                }
 
                p = ast_variable_retrieve(cfg, "general", "db-family");
                if (p) {
                        ast_copy_string(db_family, p, sizeof(db_family));
-                       db_family[sizeof(db_family) - 1] = '\0';
                }
                ast_config_destroy(cfg);
        }
index 26c7a0b..03b042b 100644 (file)
@@ -311,7 +311,7 @@ static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg,
                ast_mutex_unlock(&provlock);
        }
        if (def)
-               strncpy(cur->src, def, sizeof(cur->src) - 1);
+               ast_copy_string(cur->src, def, sizeof(cur->src));
        else
                cur->src[0] = '\0';
        v = ast_variable_browse(cfg, s);
@@ -347,15 +347,15 @@ static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg,
                        if (ast_str2tos(v->value, &cur->tos))
                                ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
                } else if (!strcasecmp(v->name, "user")) {
-                       strncpy(cur->user, v->value, sizeof(cur->user) - 1);
+                       ast_copy_string(cur->user, v->value, sizeof(cur->user));
                        if (strcmp(cur->user, v->value))
                                ast_log(LOG_WARNING, "Truncating username from '%s' to '%s' for '%s' at line %d\n", v->value, cur->user, s, v->lineno);
                } else if (!strcasecmp(v->name, "pass")) {
-                       strncpy(cur->pass, v->value, sizeof(cur->pass) - 1);
+                       ast_copy_string(cur->pass, v->value, sizeof(cur->pass));
                        if (strcmp(cur->pass, v->value))
                                ast_log(LOG_WARNING, "Truncating password from '%s' to '%s' for '%s' at line %d\n", v->value, cur->pass, s, v->lineno);
                } else if (!strcasecmp(v->name, "language")) {
-                       strncpy(cur->lang, v->value, sizeof(cur->lang) - 1);
+                       ast_copy_string(cur->lang, v->value, sizeof(cur->lang));
                        if (strcmp(cur->lang, v->value))
                                ast_log(LOG_WARNING, "Truncating language from '%s' to '%s' for '%s' at line %d\n", v->value, cur->lang, s, v->lineno);
                } else if (!strcasecmp(v->name, "flags")) {
@@ -391,7 +391,7 @@ static int iax_process_template(struct ast_config *cfg, char *s, char *def)
                        return -1;
                }
                /* Initialize entry */
-               strncpy(cur->name, s, sizeof(cur->name) - 1);
+               ast_copy_string(cur->name, s, sizeof(cur->name));
                cur->dead = 1;
        }
        if (!iax_template_parse(cur, cfg, s, def))
index 3cc6304..f36cbf6 100644 (file)
@@ -269,54 +269,47 @@ static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *le
                break;
        case ASTCHANNAME:
                if (!ast_strlen_zero(ast_channel_name(chan))) {
-                       strncpy(string_ret, ast_channel_name(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_name(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANLANGUAGE:
                if (!ast_strlen_zero(ast_channel_language(chan))) {
-                       strncpy(string_ret, ast_channel_language(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_language(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANTYPE:
-               strncpy(string_ret, ast_channel_tech(chan)->type, sizeof(string_ret));
-               string_ret[sizeof(string_ret) - 1] = '\0';
+               ast_copy_string(string_ret, ast_channel_tech(chan)->type, sizeof(string_ret));
                *var_len = strlen(string_ret);
                ret = (u_char *)string_ret;
                break;
        case ASTCHANMUSICCLASS:
                if (!ast_strlen_zero(ast_channel_musicclass(chan))) {
-                       strncpy(string_ret, ast_channel_musicclass(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_musicclass(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANBRIDGE:
                if ((bridge = ast_bridged_channel(chan)) != NULL) {
-                       strncpy(string_ret, ast_channel_name(bridge), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_name(bridge), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANMASQ:
                if (ast_channel_masq(chan) && !ast_strlen_zero(ast_channel_name(ast_channel_masq(chan)))) {
-                       strncpy(string_ret, ast_channel_name(ast_channel_masq(chan)), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_name(ast_channel_masq(chan)), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANMASQR:
                if (ast_channel_masqr(chan) && !ast_strlen_zero(ast_channel_name(ast_channel_masqr(chan)))) {
-                       strncpy(string_ret, ast_channel_name(ast_channel_masqr(chan)), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_name(ast_channel_masqr(chan)), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
@@ -330,35 +323,30 @@ static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *le
                break;
        case ASTCHANAPP:
                if (ast_channel_appl(chan)) {
-                       strncpy(string_ret, ast_channel_appl(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_appl(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANDATA:
                if (ast_channel_data(chan)) {
-                       strncpy(string_ret, ast_channel_data(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_data(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANCONTEXT:
-               strncpy(string_ret, ast_channel_context(chan), sizeof(string_ret));
-               string_ret[sizeof(string_ret) - 1] = '\0';
+               ast_copy_string(string_ret, ast_channel_context(chan), sizeof(string_ret));
                *var_len = strlen(string_ret);
                ret = (u_char *)string_ret;
                break;
        case ASTCHANMACROCONTEXT:
-               strncpy(string_ret, ast_channel_macrocontext(chan), sizeof(string_ret));
-               string_ret[sizeof(string_ret) - 1] = '\0';
+               ast_copy_string(string_ret, ast_channel_macrocontext(chan), sizeof(string_ret));
                *var_len = strlen(string_ret);
                ret = (u_char *)string_ret;
                break;
        case ASTCHANMACROEXTEN:
-               strncpy(string_ret, ast_channel_macroexten(chan), sizeof(string_ret));
-               string_ret[sizeof(string_ret) - 1] = '\0';
+               ast_copy_string(string_ret, ast_channel_macroexten(chan), sizeof(string_ret));
                *var_len = strlen(string_ret);
                ret = (u_char *)string_ret;
                break;
@@ -367,8 +355,7 @@ static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *le
                ret = (u_char *)&long_ret;
                break;
        case ASTCHANEXTEN:
-               strncpy(string_ret, ast_channel_exten(chan), sizeof(string_ret));
-               string_ret[sizeof(string_ret) - 1] = '\0';
+               ast_copy_string(string_ret, ast_channel_exten(chan), sizeof(string_ret));
                *var_len = strlen(string_ret);
                ret = (u_char *)string_ret;
                break;
@@ -378,23 +365,20 @@ static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *le
                break;
        case ASTCHANACCOUNTCODE:
                if (!ast_strlen_zero(ast_channel_accountcode(chan))) {
-                       strncpy(string_ret, ast_channel_accountcode(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_accountcode(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANFORWARDTO:
                if (!ast_strlen_zero(ast_channel_call_forward(chan))) {
-                       strncpy(string_ret, ast_channel_call_forward(chan), sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_call_forward(chan), sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANUNIQUEID:
-               strncpy(string_ret, ast_channel_uniqueid(chan), sizeof(string_ret));
-               string_ret[sizeof(string_ret) - 1] = '\0';
+               ast_copy_string(string_ret, ast_channel_uniqueid(chan), sizeof(string_ret));
                *var_len = strlen(string_ret);
                ret = (u_char *)string_ret;
                break;
@@ -420,40 +404,35 @@ static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *le
                break;
        case ASTCHANCIDDNID:
                if (ast_channel_dialed(chan)->number.str) {
-                       strncpy(string_ret, ast_channel_dialed(chan)->number.str, sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_dialed(chan)->number.str, sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANCIDNUM:
                if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
-                       strncpy(string_ret, ast_channel_caller(chan)->id.number.str, sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_caller(chan)->id.number.str, sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANCIDNAME:
                if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
-                       strncpy(string_ret, ast_channel_caller(chan)->id.name.str, sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_caller(chan)->id.name.str, sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANCIDANI:
                if (ast_channel_caller(chan)->ani.number.valid && ast_channel_caller(chan)->ani.number.str) {
-                       strncpy(string_ret, ast_channel_caller(chan)->ani.number.str, sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_caller(chan)->ani.number.str, sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
                break;
        case ASTCHANCIDRDNIS:
                if (ast_channel_redirecting(chan)->from.number.valid && ast_channel_redirecting(chan)->from.number.str) {
-                       strncpy(string_ret, ast_channel_redirecting(chan)->from.number.str, sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_redirecting(chan)->from.number.str, sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }
@@ -484,8 +463,7 @@ static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *le
                break;
        case ASTCHANTONEZONE:
                if (ast_channel_zone(chan)) {
-                       strncpy(string_ret, ast_channel_zone(chan)->country, sizeof(string_ret));
-                       string_ret[sizeof(string_ret) - 1] = '\0';
+                       ast_copy_string(string_ret, ast_channel_zone(chan)->country, sizeof(string_ret));
                        *var_len = strlen(string_ret);
                        ret = (u_char *)string_ret;
                }