[Asterisk-cvs] asterisk/channels chan_iax2.c, 1.286, 1.287 chan_zap.c, 1.443, 1.444

kpfleming at lists.digium.com kpfleming at lists.digium.com
Sun May 15 19:21:21 CDT 2005


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv19058/channels

Modified Files:
	chan_iax2.c chan_zap.c 
Log Message:
more strncpy -> ast_copy_string conversions, fixing some buglets along the way
add recommendation to CODING-GUIDELINES to use ast_copy_string instead of strncpy in new code


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.286
retrieving revision 1.287
diff -u -d -r1.286 -r1.287
--- chan_iax2.c	15 May 2005 22:05:16 -0000	1.286
+++ chan_iax2.c	15 May 2005 23:26:45 -0000	1.287
@@ -816,7 +816,7 @@
 	while(peer) {
 		if ((peer->addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
 				(peer->addr.sin_port == sin.sin_port)) {
-					strncpy(host, peer->name, len-1);
+					ast_copy_string(host, peer->name, len);
 					res = 1;
 					break;
 		}
@@ -843,9 +843,9 @@
 		tmp->autoid = -1;
 		tmp->authid = -1;
 		tmp->initid = -1;
-		/* strncpy(tmp->context, context, sizeof(tmp->context)-1); */
-		strncpy(tmp->exten, "s", sizeof(tmp->exten)-1);
-		strncpy(tmp->host, host, sizeof(tmp->host)-1);
+		/* ast_copy_string(tmp->context, context, sizeof(tmp->context)); */
+		ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
+		ast_copy_string(tmp->host, host, sizeof(tmp->host));
 #ifdef NEWJB
 		{
 			jb_info jbinfo;
@@ -1036,7 +1036,7 @@
 			iaxs[x]->lagid = ast_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
 			iaxs[x]->amaflags = amaflags;
 			ast_copy_flags(iaxs[x], (&globalflags), IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);	
-			strncpy(iaxs[x]->accountcode, accountcode, sizeof(iaxs[x]->accountcode)-1);
+			ast_copy_string(iaxs[x]->accountcode, accountcode, sizeof(iaxs[x]->accountcode));
 		} else {
 			ast_log(LOG_WARNING, "Out of resources\n");
 			ast_mutex_unlock(&iaxsl[x]);
@@ -1837,13 +1837,13 @@
 
 		ast_cli(fd, "  Status       : ");
 		if (peer->lastms < 0)
-			strncpy(status, "UNREACHABLE", sizeof(status) - 1);
+			ast_copy_string(status, "UNREACHABLE", sizeof(status));
 		else if (peer->lastms > peer->maxms)
 			snprintf(status, sizeof(status), "LAGGED (%d ms)", peer->lastms);
 		else if (peer->lastms)
 			snprintf(status, sizeof(status), "OK (%d ms)", peer->lastms);
 		else
-			strncpy(status, "UNKNOWN", sizeof(status) - 1);
+			ast_copy_string(status, "UNKNOWN", sizeof(status));
 		ast_cli(fd, "%s\n",status);
 		ast_cli(fd,"\n");
 		if (ast_test_flag(peer, IAX_TEMPONLY))
@@ -1931,7 +1931,7 @@
 		if (!ast_strlen_zero(tmp))
 			tmp[strlen(tmp) - 1] = '\0';
 		else
-			strncpy(tmp, "(none)", sizeof(tmp) - 1);
+			ast_copy_string(tmp, "(none)", sizeof(tmp));
 		y=0;
 		pc = strchr(dp->peercontext, '@');
 		if (!pc)
@@ -2664,9 +2664,9 @@
 			if (maxtime)
 				*maxtime = p->maxms;		/* Max time they should take */
 			if (context)
-				strncpy(context, p->context, AST_MAX_EXTENSION - 1);
+				ast_copy_string(context, p->context, sizeof(context));
 			if (peercontext)
-				strncpy(peercontext, p->peercontext, AST_MAX_EXTENSION - 1);
+				ast_copy_string(peercontext, p->peercontext, sizeof(peercontext));
 			if (trunk)
 				*trunk = ast_test_flag(p, IAX_TRUNK);
 			if (capability)
@@ -2674,7 +2674,7 @@
 			if (encmethods)
 				*encmethods = p->encmethods;
 			if (username)
-				strncpy(username, p->username, usernlen);
+				ast_copy_string(username, p->username, usernlen);
 			if (p->addr.sin_addr.s_addr) {
 				sin->sin_addr = p->addr.sin_addr;
 				sin->sin_port = p->addr.sin_port;
@@ -2708,7 +2708,7 @@
 						p = NULL;
 					}
 				} else
-					strncpy(secret, p->secret, seclen); /* safe */
+					ast_copy_string(secret, p->secret, seclen);
 			}
 			if (timezone)
 				snprintf(timezone, tzlen-1, "%s", p->zonetag);
@@ -2802,7 +2802,7 @@
 		ast_log(LOG_WARNING, "Line is already in use (%s)?\n", c->name);
 		return -1;
 	}
-	strncpy(host, dest, sizeof(host)-1);
+	ast_copy_string(host, dest, sizeof(host));
 	stringp=host;
 	strsep(&stringp, "/");
 	/* If no destination extension specified, use 's' */
@@ -2844,7 +2844,7 @@
 		return -1;
 	}
 	/* Keep track of the context for outgoing calls too */
-	strncpy(c->context, context, sizeof(c->context) - 1);
+	ast_copy_string(c->context, context, sizeof(c->context));
 	if (portno) {
 		sin.sin_port = htons(atoi(portno));
 	}
@@ -2891,19 +2891,19 @@
 		secret = storedsecret;
 	ast_mutex_lock(&iaxsl[callno]);
 	if (!ast_strlen_zero(c->context))
-		strncpy(iaxs[callno]->context, c->context, sizeof(iaxs[callno]->context) - 1);
+		ast_copy_string(iaxs[callno]->context, c->context, sizeof(iaxs[callno]->context));
 	if (username)
-		strncpy(iaxs[callno]->username, username, sizeof(iaxs[callno]->username)-1);
+		ast_copy_string(iaxs[callno]->username, username, sizeof(iaxs[callno]->username));
 	iaxs[callno]->encmethods = encmethods;
 	if (secret) {
 		if (secret[0] == '[') {
 			/* This is an RSA key, not a normal secret */
-			strncpy(iaxs[callno]->outkey, secret + 1, sizeof(iaxs[callno]->secret)-1);
+			ast_copy_string(iaxs[callno]->outkey, secret + 1, sizeof(iaxs[callno]->secret));
 			if (!ast_strlen_zero(iaxs[callno]->outkey)) {
 				iaxs[callno]->outkey[strlen(iaxs[callno]->outkey) - 1] = '\0';
 			}
 		} else
-			strncpy(iaxs[callno]->secret, secret, sizeof(iaxs[callno]->secret)-1);
+			ast_copy_string(iaxs[callno]->secret, secret, sizeof(iaxs[callno]->secret));
 	}
 	iax_ie_append_int(&ied, IAX_IE_FORMAT, c->nativeformats);
 	iax_ie_append_int(&ied, IAX_IE_CAPABILITY, iaxs[callno]->capability);
@@ -3206,7 +3206,7 @@
 	unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
 	struct iax_ie_data ied;
 	char tmp[256] = "", *context;
-	strncpy(tmp, dest, sizeof(tmp) - 1);
+	ast_copy_string(tmp, dest, sizeof(tmp));
 	context = strchr(tmp, '@');
 	if (context) {
 		*context = '\0';
@@ -3274,18 +3274,18 @@
 		if (!ast_strlen_zero(i->ani))
 			tmp->cid.cid_ani = strdup(i->ani);
 		if (!ast_strlen_zero(i->language))
-			strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
+			ast_copy_string(tmp->language, i->language, sizeof(tmp->language));
 		if (!ast_strlen_zero(i->dnid))
 			tmp->cid.cid_dnid = strdup(i->dnid);
 		tmp->cid.cid_pres = i->calling_pres;
 		tmp->cid.cid_ton = i->calling_ton;
 		tmp->cid.cid_tns = i->calling_tns;
 		if (!ast_strlen_zero(i->accountcode))
-			strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
+			ast_copy_string(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode));
 		if (i->amaflags)
 			tmp->amaflags = i->amaflags;
-		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
-		strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
+		ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
+		ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
 		tmp->adsicpe = i->peeradsicpe;
 		i->owner = tmp;
 		i->capability = capability;
@@ -3971,11 +3971,11 @@
 			continue;
 
 		if (!ast_strlen_zero(user->secret)) {
-  			strncpy(auth,user->secret,sizeof(auth)-1);
+  			ast_copy_string(auth,user->secret,sizeof(auth));
 		} else if (!ast_strlen_zero(user->inkeys)) {
   			snprintf(auth, sizeof(auth), "Key: %-15.15s ", user->inkeys);
  		} else
-			strncpy(auth, "-no secret-", sizeof(auth) - 1);
+			ast_copy_string(auth, "-no secret-", sizeof(auth));
 
 		if(ast_test_flag(user,IAX_CODEC_NOCAP))
 			pstr = "REQ Only";
@@ -4064,10 +4064,10 @@
 		if (!ast_strlen_zero(peer->username))
 			snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username);
 		else
-			strncpy(name, peer->name, sizeof(name) - 1);
+			ast_copy_string(name, peer->name, sizeof(name));
 		if (peer->maxms) {
 			if (peer->lastms < 0) {
-				strncpy(status, "UNREACHABLE", sizeof(status) - 1);
+				ast_copy_string(status, "UNREACHABLE", sizeof(status));
 				offline_peers++;
 			}
 			else if (peer->lastms > peer->maxms)  {
@@ -4079,14 +4079,14 @@
 				online_peers++;
 			}
 			else  {
-				strncpy(status, "UNKNOWN", sizeof(status) - 1);
+				ast_copy_string(status, "UNKNOWN", sizeof(status));
 				offline_peers++;
 			}
 		} else {
-			strncpy(status, "Unmonitored", sizeof(status) - 1);
+			ast_copy_string(status, "Unmonitored", sizeof(status));
 			unmonitored_peers++;
 		}
-		strncpy(nm, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->mask), sizeof(nm)-1);
+		ast_copy_string(nm, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->mask), sizeof(nm));
 
 		snprintf(srch, sizeof(srch), FORMAT, name, 
 					peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
@@ -4196,7 +4196,7 @@
 		if (reg->us.sin_addr.s_addr) 
 			snprintf(perceived, sizeof(perceived), "%s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), reg->us.sin_addr), ntohs(reg->us.sin_port));
 		else
-			strncpy(perceived, "<Unregistered>", sizeof(perceived) - 1);
+			ast_copy_string(perceived, "<Unregistered>", sizeof(perceived));
 		ast_cli(fd, FORMAT, host, 
 					reg->username, perceived, reg->refresh, regstate2str(reg->regstate));
 	}
@@ -4585,23 +4585,23 @@
 	if (!iaxs[callno])
 		return res;
 	if (ies->called_number)
-		strncpy(iaxs[callno]->exten, ies->called_number, sizeof(iaxs[callno]->exten) - 1);
+		ast_copy_string(iaxs[callno]->exten, ies->called_number, sizeof(iaxs[callno]->exten));
 	if (ies->calling_number) {
 		ast_shrink_phone_number(ies->calling_number);
-		strncpy(iaxs[callno]->cid_num, ies->calling_number, sizeof(iaxs[callno]->cid_num) - 1);
+		ast_copy_string(iaxs[callno]->cid_num, ies->calling_number, sizeof(iaxs[callno]->cid_num));
 	}
 	if (ies->calling_name)
-		strncpy(iaxs[callno]->cid_name, ies->calling_name, sizeof(iaxs[callno]->cid_name) - 1);
+		ast_copy_string(iaxs[callno]->cid_name, ies->calling_name, sizeof(iaxs[callno]->cid_name));
 	if (ies->calling_ani)
-		strncpy(iaxs[callno]->ani, ies->calling_ani, sizeof(iaxs[callno]->ani) - 1);
+		ast_copy_string(iaxs[callno]->ani, ies->calling_ani, sizeof(iaxs[callno]->ani));
 	if (ies->dnid)
-		strncpy(iaxs[callno]->dnid, ies->dnid, sizeof(iaxs[callno]->dnid)-1);
+		ast_copy_string(iaxs[callno]->dnid, ies->dnid, sizeof(iaxs[callno]->dnid));
 	if (ies->called_context)
-		strncpy(iaxs[callno]->context, ies->called_context, sizeof(iaxs[callno]->context)-1);
+		ast_copy_string(iaxs[callno]->context, ies->called_context, sizeof(iaxs[callno]->context));
 	if (ies->language)
-		strncpy(iaxs[callno]->language, ies->language, sizeof(iaxs[callno]->language)-1);
+		ast_copy_string(iaxs[callno]->language, ies->language, sizeof(iaxs[callno]->language));
 	if (ies->username)
-		strncpy(iaxs[callno]->username, ies->username, sizeof(iaxs[callno]->username)-1);
+		ast_copy_string(iaxs[callno]->username, ies->username, sizeof(iaxs[callno]->username));
 	if (ies->calling_ton > -1)
 		iaxs[callno]->calling_ton = ies->calling_ton;
 	if (ies->calling_tns > -1)
@@ -4701,19 +4701,19 @@
 		iaxs[callno]->encmethods = user->encmethods;
 		/* Store the requested username if not specified */
 		if (ast_strlen_zero(iaxs[callno]->username))
-			strncpy(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username)-1);
+			ast_copy_string(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username));
 		/* Store whether this is a trunked call, too, of course, and move if appropriate */
 		ast_copy_flags(iaxs[callno], user, IAX_TRUNK);
 		iaxs[callno]->capability = user->capability;
 		/* And use the default context */
 		if (ast_strlen_zero(iaxs[callno]->context)) {
 			if (user->contexts)
-				strncpy(iaxs[callno]->context, user->contexts->context, sizeof(iaxs[callno]->context)-1);
+				ast_copy_string(iaxs[callno]->context, user->contexts->context, sizeof(iaxs[callno]->context));
 			else
-				strncpy(iaxs[callno]->context, context, sizeof(iaxs[callno]->context)-1);
+				ast_copy_string(iaxs[callno]->context, context, sizeof(iaxs[callno]->context));
 		}
 		/* And any input keys */
-		strncpy(iaxs[callno]->inkeys, user->inkeys, sizeof(iaxs[callno]->inkeys) - 1);
+		ast_copy_string(iaxs[callno]->inkeys, user->inkeys, sizeof(iaxs[callno]->inkeys));
 		/* And the permitted authentication methods */
 		iaxs[callno]->authmethods = user->authmethods;
 		/* If they have callerid, override the given caller id.  Always store the ANI */
@@ -4721,20 +4721,20 @@
 			if (ast_test_flag(user, IAX_HASCALLERID)) {
 				iaxs[callno]->calling_tns = 0;
 				iaxs[callno]->calling_ton = 0;
-				strncpy(iaxs[callno]->cid_num, user->cid_num, sizeof(iaxs[callno]->cid_num)-1);
-				strncpy(iaxs[callno]->cid_name, user->cid_name, sizeof(iaxs[callno]->cid_name)-1);
+				ast_copy_string(iaxs[callno]->cid_num, user->cid_num, sizeof(iaxs[callno]->cid_num));
+				ast_copy_string(iaxs[callno]->cid_name, user->cid_name, sizeof(iaxs[callno]->cid_name));
 				iaxs[callno]->calling_pres = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
 			}
-			strncpy(iaxs[callno]->ani, user->cid_num, sizeof(iaxs[callno]->ani)-1);
+			ast_copy_string(iaxs[callno]->ani, user->cid_num, sizeof(iaxs[callno]->ani));
 		} else {
 			iaxs[callno]->calling_pres = AST_PRES_NUMBER_NOT_AVAILABLE;
 		}
 		if (!ast_strlen_zero(user->accountcode))
-			strncpy(iaxs[callno]->accountcode, user->accountcode, sizeof(iaxs[callno]->accountcode)-1);
+			ast_copy_string(iaxs[callno]->accountcode, user->accountcode, sizeof(iaxs[callno]->accountcode));
 		if (user->amaflags)
 			iaxs[callno]->amaflags = user->amaflags;
 		if (!ast_strlen_zero(user->language))
-			strncpy(iaxs[callno]->language, user->language, sizeof(iaxs[callno]->language)-1);
+			ast_copy_string(iaxs[callno]->language, user->language, sizeof(iaxs[callno]->language));
 		ast_copy_flags(iaxs[callno], user, IAX_NOTRANSFER | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);	
 		/* Keep this check last */
 		if (!ast_strlen_zero(user->dbsecret)) {
@@ -4755,7 +4755,7 @@
 				}
 			}
 		} else
-			strncpy(iaxs[callno]->secret, user->secret, sizeof(iaxs[callno]->secret) - 1); 
+			ast_copy_string(iaxs[callno]->secret, user->secret, sizeof(iaxs[callno]->secret)); 
 		res = 0;
 	}
 	ast_set2_flag(iaxs[callno], iax2_getpeertrunk(*sin), IAX_TRUNK);	
@@ -4824,17 +4824,17 @@
 	if (!(p->state & IAX_STATE_AUTHENTICATED))
 		return res;
 	if (ies->password)
-		strncpy(secret, ies->password, sizeof(secret) - 1);
+		ast_copy_string(secret, ies->password, sizeof(secret));
 	if (ies->md5_result)
-		strncpy(md5secret, ies->md5_result, sizeof(md5secret)-1);
+		ast_copy_string(md5secret, ies->md5_result, sizeof(md5secret));
 	if (ies->rsa_result)
-		strncpy(rsasecret, ies->rsa_result, sizeof(rsasecret)-1);
+		ast_copy_string(rsasecret, ies->rsa_result, sizeof(rsasecret));
 	if ((p->authmethods & IAX_AUTH_RSA) && !ast_strlen_zero(rsasecret) && !ast_strlen_zero(p->inkeys)) {
 		struct ast_key *key;
 		char *keyn;
 		char tmpkey[256] = "";
 		char *stringp=NULL;
-		strncpy(tmpkey, p->inkeys, sizeof(tmpkey) - 1);
+		ast_copy_string(tmpkey, p->inkeys, sizeof(tmpkey));
 		stringp=tmpkey;
 		keyn = strsep(&stringp, ":");
 		while(keyn) {
@@ -4890,13 +4890,13 @@
 	iaxs[callno]->state &= ~IAX_STATE_AUTHENTICATED;
 	iaxs[callno]->peer[0] = '\0';
 	if (ies->username)
-		strncpy(peer, ies->username, sizeof(peer) - 1);
+		ast_copy_string(peer, ies->username, sizeof(peer));
 	if (ies->password)
-		strncpy(secret, ies->password, sizeof(secret) - 1);
+		ast_copy_string(secret, ies->password, sizeof(secret));
 	if (ies->md5_result)
-		strncpy(md5secret, ies->md5_result, sizeof(md5secret)-1);
+		ast_copy_string(md5secret, ies->md5_result, sizeof(md5secret));
 	if (ies->rsa_result)
-		strncpy(rsasecret, ies->rsa_result, sizeof(rsasecret)-1);
+		ast_copy_string(rsasecret, ies->rsa_result, sizeof(rsasecret));
 	if (ies->refresh)
 		expire = ies->refresh;
 
@@ -4931,14 +4931,14 @@
 			destroy_peer(p);
 		return -1;
 	}
-	strncpy(iaxs[callno]->secret, p->secret, sizeof(iaxs[callno]->secret)-1);
-	strncpy(iaxs[callno]->inkeys, p->inkeys, sizeof(iaxs[callno]->inkeys)-1);
+	ast_copy_string(iaxs[callno]->secret, p->secret, sizeof(iaxs[callno]->secret));
+	ast_copy_string(iaxs[callno]->inkeys, p->inkeys, sizeof(iaxs[callno]->inkeys));
 	/* Check secret against what we have on file */
 	if (!ast_strlen_zero(rsasecret) && (p->authmethods & IAX_AUTH_RSA) && !ast_strlen_zero(iaxs[callno]->challenge)) {
 		if (!ast_strlen_zero(p->inkeys)) {
 			char tmpkeys[256] = "";
 			char *stringp=NULL;
-			strncpy(tmpkeys, p->inkeys, sizeof(tmpkeys) - 1);
+			ast_copy_string(tmpkeys, p->inkeys, sizeof(tmpkeys));
 			stringp=tmpkeys;
 			keyn = strsep(&stringp, ":");
 			while(keyn) {
@@ -5007,7 +5007,7 @@
 			destroy_peer(p);
 		return -1;
 	}
-	strncpy(iaxs[callno]->peer, peer, sizeof(iaxs[callno]->peer)-1);
+	ast_copy_string(iaxs[callno]->peer, peer, sizeof(iaxs[callno]->peer));
 	/* Choose lowest expirey number */
 	if (expire && (expire < iaxs[callno]->expirey)) 
 		iaxs[callno]->expirey = expire;
@@ -5085,9 +5085,9 @@
 	memset(&ied, 0, sizeof(ied));
 	
 	if (ies->username)
-		strncpy(p->username, ies->username, sizeof(p->username) - 1);
+		ast_copy_string(p->username, ies->username, sizeof(p->username));
 	if (ies->challenge)
-		strncpy(p->challenge, ies->challenge, sizeof(p->challenge)-1);
+		ast_copy_string(p->challenge, ies->challenge, sizeof(p->challenge));
 	if (ies->authmethods)
 		authmethods = ies->authmethods;
 	if (authmethods & IAX_AUTH_MD5)
@@ -5174,7 +5174,7 @@
 	struct iax2_dpcache *dp, *prev;
 	
 	if (ies->called_number)
-		strncpy(exten, ies->called_number, sizeof(exten)-1);
+		ast_copy_string(exten, ies->called_number, sizeof(exten));
 
 	if (ies->dpstatus & IAX_DPSTATUS_EXISTS)
 		status = CACHE_FLAG_EXISTS;
@@ -5296,7 +5296,7 @@
 	if (ies->apparent_addr)
 		memcpy(&us, ies->apparent_addr, sizeof(us));
 	if (ies->username)
-		strncpy(peer, ies->username, sizeof(peer) - 1);
+		ast_copy_string(peer, ies->username, sizeof(peer));
 	if (ies->refresh)
 		refresh = ies->refresh;
 	if (ies->calling_number) {
@@ -5350,7 +5350,7 @@
 	struct ast_hostent ahp; struct hostent *hp;
 	if (!value)
 		return -1;
-	strncpy(copy, value, sizeof(copy)-1);
+	ast_copy_string(copy, value, sizeof(copy));
 	stringp=copy;
 	username = strsep(&stringp, "@");
 	hostname = strsep(&stringp, "@");
@@ -5377,9 +5377,9 @@
 	reg = malloc(sizeof(struct iax2_registry));
 	if (reg) {
 		memset(reg, 0, sizeof(struct iax2_registry));
-		strncpy(reg->username, username, sizeof(reg->username)-1);
+		ast_copy_string(reg->username, username, sizeof(reg->username));
 		if (secret)
-			strncpy(reg->secret, secret, sizeof(reg->secret)-1);
+			ast_copy_string(reg->secret, secret, sizeof(reg->secret));
 		reg->expire = -1;
 		reg->refresh = IAX_DEFAULT_REG_EXPIRE;
 		reg->addr.sin_family = AF_INET;
@@ -5400,7 +5400,7 @@
 	unsigned char multi[256]="";
 	char *stringp, *ext;
 	if (!ast_strlen_zero(regcontext)) {
-		strncpy(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi) - 1);
+		ast_copy_string(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi));
 		stringp = multi;
 		while((ext = strsep(&stringp, "&"))) {
 			if (onoff) {
@@ -5598,9 +5598,9 @@
 	if (ies->authmethods)
 		authmethods = ies->authmethods;
 	if (ies->username)
-		strncpy(peer, ies->username, sizeof(peer) - 1);
+		ast_copy_string(peer, ies->username, sizeof(peer));
 	if (ies->challenge)
-		strncpy(challenge, ies->challenge, sizeof(challenge) - 1);
+		ast_copy_string(challenge, ies->challenge, sizeof(challenge));
 	memset(&ied, 0, sizeof(ied));
 	reg = iaxs[callno]->reg;
 	if (reg) {
@@ -5617,7 +5617,7 @@
 			iax_ie_append_short(&ied, IAX_IE_REFRESH, reg->refresh);
 			if (reg->secret[0] == '[') {
 				char tmpkey[256];
-				strncpy(tmpkey, reg->secret + 1, sizeof(tmpkey) - 1);
+				ast_copy_string(tmpkey, reg->secret + 1, sizeof(tmpkey));
 				tmpkey[strlen(tmpkey) - 1] = '\0';
 				res = authenticate(challenge, NULL, tmpkey, authmethods, &ied, sin, NULL, NULL);
 			} else
@@ -5943,8 +5943,8 @@
 	if (dpr) {
 		memset(dpr, 0, sizeof(struct dpreq_data));
 		dpr->callno = callno;
-		strncpy(dpr->context, context, sizeof(dpr->context) - 1);
-		strncpy(dpr->callednum, callednum, sizeof(dpr->callednum) - 1);
+		ast_copy_string(dpr->context, context, sizeof(dpr->context));
+		ast_copy_string(dpr->callednum, callednum, sizeof(dpr->callednum));
 		if (callerid)
 			dpr->callerid = strdup(callerid);
 		if (ast_pthread_create(&newthread, NULL, dp_lookup_thread, dpr)) {
@@ -5993,8 +5993,8 @@
 		chan1m->writeformat = chan1->writeformat;
 		ast_channel_masquerade(chan1m, chan1);
 		/* Setup the extensions and such */
-		strncpy(chan1m->context, chan1->context, sizeof(chan1m->context) - 1);
-		strncpy(chan1m->exten, chan1->exten, sizeof(chan1m->exten) - 1);
+		ast_copy_string(chan1m->context, chan1->context, sizeof(chan1m->context));
+		ast_copy_string(chan1m->exten, chan1->exten, sizeof(chan1m->exten));
 		chan1m->priority = chan1->priority;
 		
 		/* We make a clone of the peer channel too, so we can play
@@ -6005,8 +6005,8 @@
 		chan2m->writeformat = chan2->writeformat;
 		ast_channel_masquerade(chan2m, chan2);
 		/* Setup the extensions and such */
-		strncpy(chan2m->context, chan2->context, sizeof(chan2m->context) - 1);
-		strncpy(chan2m->exten, chan2->exten, sizeof(chan2m->exten) - 1);
+		ast_copy_string(chan2m->context, chan2->context, sizeof(chan2m->context));
+		ast_copy_string(chan2m->exten, chan2->exten, sizeof(chan2m->exten));
 		chan2m->priority = chan2->priority;
 		if (ast_do_masquerade(chan2m)) {
 			ast_log(LOG_WARNING, "Masquerade failed :(\n");
@@ -7130,7 +7130,7 @@
 			case IAX_COMMAND_DIAL:
 				if (iaxs[fr.callno]->state & IAX_STATE_TBD) {
 					iaxs[fr.callno]->state &= ~IAX_STATE_TBD;
-					strncpy(iaxs[fr.callno]->exten, ies.called_number ? ies.called_number : "s", sizeof(iaxs[fr.callno]->exten)-1);	
+					ast_copy_string(iaxs[fr.callno]->exten, ies.called_number ? ies.called_number : "s", sizeof(iaxs[fr.callno]->exten));	
 					if (!ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num)) {
 						if (authdebug)
 							ast_log(LOG_NOTICE, "Rejected dial attempt from %s, request '%s@%s' does not exist\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
@@ -7632,7 +7632,7 @@
 	int usejitterbuf = ast_test_flag((&globalflags), IAX_USEJITTERBUF);
 	int forcejitterbuf = ast_test_flag((&globalflags), IAX_FORCEJITTERBUF);
 
-	strncpy(s, (char *)data, sizeof(s)-1);
+	ast_copy_string(s, (char *)data, sizeof(s));
 	/* FIXME The next two lines seem useless */
 	stringp=s;
 	strsep(&stringp, "/");
@@ -7678,7 +7678,7 @@
 	ast_set2_flag(iaxs[callno], usejitterbuf, IAX_USEJITTERBUF);	
 	ast_set2_flag(iaxs[callno], forcejitterbuf, IAX_FORCEJITTERBUF);	
 	if (found)
-		strncpy(iaxs[callno]->host, hostname, sizeof(iaxs[callno]->host) - 1);
+		ast_copy_string(iaxs[callno]->host, hostname, sizeof(iaxs[callno]->host));
 	c = ast_iax2_new(callno, AST_STATE_DOWN, capability);
 	ast_mutex_unlock(&iaxsl[callno]);
 	if (c) {
@@ -7767,7 +7767,7 @@
 {
 	struct iax2_context *con = malloc(sizeof(struct iax2_context));
 	if (con) {
-		strncpy(con->context, context, sizeof(con->context)-1);
+		ast_copy_string(con->context, context, sizeof(con->context));
 		con->next = NULL;
 	}
 	return con;
@@ -7833,7 +7833,7 @@
 		peer->encmethods = iax2_encryption;
 		peer->secret[0] = '\0';
 		if (!found) {
-			strncpy(peer->name, name, sizeof(peer->name)-1);
+			ast_copy_string(peer->name, name, sizeof(peer->name));
 			peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
 			peer->expirey = expirey;
 		}
@@ -7845,11 +7845,11 @@
 					strncpy(peer->secret + strlen(peer->secret), ";", sizeof(peer->secret)-strlen(peer->secret) - 1);
 					strncpy(peer->secret + strlen(peer->secret), v->value, sizeof(peer->secret)-strlen(peer->secret) - 1);
 				} else
-					strncpy(peer->secret, v->value, sizeof(peer->secret)-1);
+					ast_copy_string(peer->secret, v->value, sizeof(peer->secret));
 			} else if (!strcasecmp(v->name, "mailbox")) {
-				strncpy(peer->mailbox, v->value, sizeof(peer->mailbox) - 1);
+				ast_copy_string(peer->mailbox, v->value, sizeof(peer->mailbox));
 			} else if (!strcasecmp(v->name, "dbsecret")) 
-				strncpy(peer->dbsecret, v->value, sizeof(peer->dbsecret)-1);
+				ast_copy_string(peer->dbsecret, v->value, sizeof(peer->dbsecret));
 			else if (!strcasecmp(v->name, "mailboxdetail"))
 				ast_set2_flag(peer, ast_true(v->value), IAX_MESSAGEDETAIL);	
 			else if (!strcasecmp(v->name, "trunktimestamps"))
@@ -7910,19 +7910,19 @@
 				inet_aton(v->value, &peer->mask);
 			} else if (!strcasecmp(v->name, "context")) {
 				if (ast_strlen_zero(peer->context))
-					strncpy(peer->context, v->value, sizeof(peer->context) - 1);
+					ast_copy_string(peer->context, v->value, sizeof(peer->context));
 			} else if (!strcasecmp(v->name, "regexten")) {
-				strncpy(peer->regexten, v->value, sizeof(peer->regexten) - 1);
+				ast_copy_string(peer->regexten, v->value, sizeof(peer->regexten));
 			} else if (!strcasecmp(v->name, "peercontext")) {
 				if (ast_strlen_zero(peer->peercontext))
-					strncpy(peer->peercontext, v->value, sizeof(peer->peercontext) - 1);
+					ast_copy_string(peer->peercontext, v->value, sizeof(peer->peercontext));
 			} else if (!strcasecmp(v->name, "port")) {
 				if (ast_test_flag(peer, IAX_DYNAMIC))
 					peer->defaddr.sin_port = htons(atoi(v->value));
 				else
 					peer->addr.sin_port = htons(atoi(v->value));
 			} else if (!strcasecmp(v->name, "username")) {
-				strncpy(peer->username, v->value, sizeof(peer->username)-1);
+				ast_copy_string(peer->username, v->value, sizeof(peer->username));
 			} else if (!strcasecmp(v->name, "allow")) {
 				ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 1);
 			} else if (!strcasecmp(v->name, "disallow")) {
@@ -7934,9 +7934,9 @@
 			} else if (!strcasecmp(v->name, "sendani")) {
 				ast_set2_flag(peer, ast_true(v->value), IAX_SENDANI);	
 			} else if (!strcasecmp(v->name, "inkeys")) {
-				strncpy(peer->inkeys, v->value, sizeof(peer->inkeys) - 1);
+				ast_copy_string(peer->inkeys, v->value, sizeof(peer->inkeys));
 			} else if (!strcasecmp(v->name, "outkey")) {
-				strncpy(peer->outkey, v->value, sizeof(peer->outkey) - 1);
+				ast_copy_string(peer->outkey, v->value, sizeof(peer->outkey));
 			} else if (!strcasecmp(v->name, "qualify")) {
 				if (!strcasecmp(v->value, "no")) {
 					peer->maxms = 0;
@@ -7947,7 +7947,7 @@
 					peer->maxms = 0;
 				}
 			} else if (!strcasecmp(v->name, "timezone")) {
-				strncpy(peer->zonetag, v->value, sizeof(peer->zonetag)-1);	
+				ast_copy_string(peer->zonetag, v->value, sizeof(peer->zonetag));
 			}/* else if (strcasecmp(v->name,"type")) */
 			/*	ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
 			v=v->next;
@@ -8015,8 +8015,8 @@
 		user->prefs = prefs;
 		user->capability = iax2_capability;
 		user->encmethods = iax2_encryption;
-		strncpy(user->name, name, sizeof(user->name)-1);
-		strncpy(user->language, language, sizeof(user->language) - 1);
+		ast_copy_string(user->name, name, sizeof(user->name));
+		ast_copy_string(user->language, language, sizeof(user->language));
 		ast_copy_flags(user, (&globalflags), IAX_USEJITTERBUF);	
 		ast_copy_flags(user, (&globalflags), IAX_FORCEJITTERBUF);	
 		ast_copy_flags(user, (&globalflags), IAX_CODEC_USER_FIRST);
@@ -8075,20 +8075,20 @@
 			} else if (!strcasecmp(v->name, "forcejitterbuffer")) {
 				ast_set2_flag(user, ast_true(v->value), IAX_FORCEJITTERBUF);	
 			} else if (!strcasecmp(v->name, "dbsecret")) {
-				strncpy(user->dbsecret, v->value, sizeof(user->dbsecret)-1);
+				ast_copy_string(user->dbsecret, v->value, sizeof(user->dbsecret));
 			} else if (!strcasecmp(v->name, "secret")) {
 				if (!ast_strlen_zero(user->secret)) {
 					strncpy(user->secret + strlen(user->secret), ";", sizeof(user->secret) - strlen(user->secret) - 1);
 					strncpy(user->secret + strlen(user->secret), v->value, sizeof(user->secret) - strlen(user->secret) - 1);
 				} else
-					strncpy(user->secret, v->value, sizeof(user->secret)-1);
+					ast_copy_string(user->secret, v->value, sizeof(user->secret));
 			} else if (!strcasecmp(v->name, "callerid")) {
 				ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
 				ast_set_flag(user, IAX_HASCALLERID);	
 			} 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, "language")) {
-				strncpy(user->language, v->value, sizeof(user->language)-1);
+				ast_copy_string(user->language, v->value, sizeof(user->language));
 			} else if (!strcasecmp(v->name, "amaflags")) {
 				format = ast_cdr_amaflags2int(v->value);
 				if (format < 0) {
@@ -8097,7 +8097,7 @@
 					user->amaflags = format;
 				}
 			} else if (!strcasecmp(v->name, "inkeys")) {
-				strncpy(user->inkeys, v->value, sizeof(user->inkeys) - 1);
+				ast_copy_string(user->inkeys, v->value, sizeof(user->inkeys));
 			}/* else if (strcasecmp(v->name,"type")) */
 			/*	ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
 			v = v->next;
@@ -8398,7 +8398,7 @@
 		} else if (!strcasecmp(v->name, "iaxcompat")) {
 			iaxcompat = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "regcontext")) {
-			strncpy(regcontext, v->value, sizeof(regcontext) - 1);
+			ast_copy_string(regcontext, v->value, sizeof(regcontext));
 			/* Create context if it doesn't exist already */
 			if (!ast_context_find(regcontext))
 				ast_context_create(NULL, regcontext, channeltype);
@@ -8418,7 +8418,7 @@
 			else
 				ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
 		} else if (!strcasecmp(v->name, "accountcode")) {
-			strncpy(accountcode, v->value, sizeof(accountcode)-1);
+			ast_copy_string(accountcode, v->value, sizeof(accountcode));
 		} else if (!strcasecmp(v->name, "amaflags")) {
 			format = ast_cdr_amaflags2int(v->value);
 			if (format < 0) {
@@ -8427,7 +8427,7 @@
 				amaflags = format;
 			}
 		} else if (!strcasecmp(v->name, "language")) {
-                        strncpy(language, v->value, sizeof(language) - 1);
+                        ast_copy_string(language, v->value, sizeof(language));
 		} /*else if (strcasecmp(v->name,"type")) */
 		/*	ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
 		v = v->next;
@@ -8473,8 +8473,8 @@
 	char *config = "iax.conf";
 	struct iax2_registry *reg;
 	struct iax2_peer *peer;
-	strncpy(accountcode, "", sizeof(accountcode)-1);
-	strncpy(language, "", sizeof(language)-1);
+	ast_copy_string(accountcode, "", sizeof(accountcode));
+	ast_copy_string(language, "", sizeof(language));
 	amaflags = 0;
 	delayreject = 0;
 	ast_clear_flag((&globalflags), IAX_NOTRANSFER);	
@@ -8530,7 +8530,7 @@
 	}
 	memset(&ied, 0, sizeof(ied));
 	/* No match found, we need to create a new one */
-	strncpy(st, data, sizeof(st)-1);
+	ast_copy_string(st, data, sizeof(st));
 	/* Grab the host */
 	s = strchr(st, '/');
 	if (s) {
@@ -8565,7 +8565,7 @@
 		return -1;
 	}
 	ast_mutex_lock(&iaxsl[callno]);
-	strncpy(iaxs[callno]->dproot, data, sizeof(iaxs[callno]->dproot)-1);
+	ast_copy_string(iaxs[callno]->dproot, data, sizeof(iaxs[callno]->dproot));
 	iaxs[callno]->capability = IAX_CAPABILITY_FULLBANDWIDTH;
 
 	iax_ie_append_short(&ied, IAX_IE_VERSION, IAX_PROTO_VERSION);
@@ -8578,7 +8578,7 @@
 	iax_ie_append_int(&ied, IAX_IE_CAPABILITY, IAX_CAPABILITY_FULLBANDWIDTH);
 	/* Keep password handy */
 	if (password)
-		strncpy(iaxs[callno]->secret, password, sizeof(iaxs[callno]->secret)-1);
+		ast_copy_string(iaxs[callno]->secret, password, sizeof(iaxs[callno]->secret));
 #if 0
 	/* XXX Need equivalent XXX */
 	if (option_verbose > 2)
@@ -8643,8 +8643,8 @@
 			return NULL;
 		}
 		memset(dp, 0, sizeof(struct iax2_dpcache));
-		strncpy(dp->peercontext, data, sizeof(dp->peercontext)-1);
-		strncpy(dp->exten, exten, sizeof(dp->exten)-1);
+		ast_copy_string(dp->peercontext, data, sizeof(dp->peercontext));
+		ast_copy_string(dp->exten, exten, sizeof(dp->exten));
 		gettimeofday(&dp->expirey, NULL);
 		dp->orig = dp->expirey;
 		/* Expires in 30 mins by default */
@@ -8835,7 +8835,7 @@
 	dp = find_cache(chan, data, context, exten, priority);
 	if (dp) {
 		if (dp->flags & CACHE_FLAG_EXISTS) {
-			strncpy(odata, data, sizeof(odata)-1);
+			ast_copy_string(odata, data, sizeof(odata));
 			ncontext = strchr(odata, '/');
 			if (ncontext) {
 				*ncontext = '\0';
@@ -8872,7 +8872,7 @@
 	char tmp[256] = "";
 	int res = AST_DEVICE_INVALID;
 
-	strncpy(tmp, dest, sizeof(tmp) - 1);
+	ast_copy_string(tmp, dest, sizeof(tmp));
 	host = strchr(tmp, '@');
 	if (host) {
 		*host = '\0';

Index: chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.443
retrieving revision 1.444
diff -u -d -r1.443 -r1.444
--- chan_zap.c	12 May 2005 21:11:42 -0000	1.443
+++ chan_zap.c	15 May 2005 23:26:45 -0000	1.444
@@ -1602,8 +1602,8 @@
 #endif
 	char dest[256]; /* must be same length as p->dialdest */
 	ast_mutex_lock(&p->lock);
-	strncpy(dest, rdest, sizeof(dest) - 1);
-	strncpy(p->dialdest, rdest, sizeof(dest) - 1);
+	ast_copy_string(dest, rdest, sizeof(dest));
+	ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
 	if ((ast->_state == AST_STATE_BUSY)) {
 		p->subs[SUB_REAL].needbusy = 1;
 		ast_mutex_unlock(&p->lock);
@@ -1692,11 +1692,11 @@
 			/* Call waiting call */
 			p->callwaitrings = 0;
 			if (ast->cid.cid_num)
-				strncpy(p->callwait_num, ast->cid.cid_num, sizeof(p->callwait_num)-1);
+				ast_copy_string(p->callwait_num, ast->cid.cid_num, sizeof(p->callwait_num));
 			else
 				p->callwait_num[0] = '\0';
 			if (ast->cid.cid_name)
-				strncpy(p->callwait_name, ast->cid.cid_name, sizeof(p->callwait_name)-1);
+				ast_copy_string(p->callwait_name, ast->cid.cid_name, sizeof(p->callwait_name));
 			else
 				p->callwait_name[0] = '\0';
 			/* Call waiting tone instead */
@@ -1712,11 +1712,11 @@
 		n = ast->cid.cid_name;
 		l = ast->cid.cid_num;
 		if (l)
-			strncpy(p->lastcid_num, l, sizeof(p->lastcid_num) - 1);
+			ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
 		else
 			p->lastcid_num[0] = '\0';
 		if (n)
-			strncpy(p->lastcid_name, n, sizeof(p->lastcid_name) - 1);
+			ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
 		else
 			p->lastcid_name[0] = '\0';
 		ast_setstate(ast, AST_STATE_RINGING);
@@ -1802,7 +1802,7 @@
 			p->whichwink = 0;
 		} else
 		if (p->sig == SIG_E911) {
-			strncpy(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr) - 1);
+			ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
 		} else
 		if (p->sig == SIG_FEATB) {
 			snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c + p->stripmsd);
@@ -2134,12 +2134,12 @@
 	zt_confmute(p, 0);
 	restore_gains(p);
 	if (p->origcid_num) {
-		strncpy(p->cid_num, p->origcid_num, sizeof(p->cid_num) - 1);
+		ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
 		free(p->origcid_num);
 		p->origcid_num = NULL;
 	}	
 	if (p->origcid_name) {
-		strncpy(p->cid_name, p->origcid_name, sizeof(p->cid_name) - 1);
+		ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
 		free(p->origcid_name);
 		p->origcid_name = NULL;
 	}	
@@ -3330,7 +3330,7 @@
 				zt_enable_ec(p);
 				if (p->echobreak) {
 					zt_train_ec(p);
-					strncpy(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr) - 1);
+					ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
 					p->dop.op = ZT_DIAL_OP_REPLACE;
 					res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
 					p->echobreak = 0;
@@ -3511,7 +3511,7 @@
 				else
 					c = p->dialdest;
 				if (*c) snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
-				else strncpy(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr) - 1);
+				else ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
 				if (strlen(p->dop.dialstr) > 4) {
 					memset(p->echorest, 'w', sizeof(p->echorest) - 1);
 					strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
@@ -3711,9 +3711,9 @@
 						if (p->threewaycalling && !check_for_conference(p)) {
 							if (p->zaptrcallerid && p->owner) {
 								if (p->owner->cid.cid_num)
-									strncpy(cid_num, p->owner->cid.cid_num, sizeof(cid_num) - 1);
+									ast_copy_string(cid_num, p->owner->cid.cid_num, sizeof(cid_num));
 								if (p->owner->cid.cid_name)
-									strncpy(cid_name, p->owner->cid.cid_name, sizeof(cid_name) - 1);
+									ast_copy_string(cid_name, p->owner->cid.cid_name, sizeof(cid_name));
 							}
 							/* XXX This section needs much more error checking!!! XXX */
 							/* Start a 3-way call if feasible */
@@ -3724,24 +3724,12 @@
 									/* Make new channel */
 									chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
 									if (p->zaptrcallerid) {
-										if (!p->origcid_num) {
-											p->origcid_num = malloc(strlen(p->cid_num) + 1);
-											if (p->origcid_num) {
-												strncpy(p->origcid_num, p->cid_num, strlen(p->cid_num)); /* safe */
-												/* make sure p->origcallerid is terminated */
-												p->origcid_num[strlen(p->cid_num)] = '\0';
-											}
-										}
-										if (!p->origcid_name) {
-											p->origcid_name = malloc(strlen(p->cid_name) + 1);
-											if (p->origcid_name) {
-												strncpy(p->origcid_name, p->cid_name, strlen(p->cid_name)); /* safe */
-												/* make sure p->origcallerid is terminated */
-												p->origcid_name[strlen(p->cid_name)] = '\0';
-											}
-										}
-										strncpy(p->cid_num, cid_num, sizeof(p->cid_num) -1);
-										strncpy(p->cid_name, cid_name, sizeof(p->cid_name) -1);
+										if (!p->origcid_num)
+											p->origcid_num = strdup(p->cid_num);
+										if (!p->origcid_name)
+											p->origcid_name = strdup(p->cid_name);
+										ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
+										ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
 									}
 									/* Swap things around between the three-way and real call */
 									swap_subs(p, SUB_THREEWAY, SUB_REAL);
@@ -3852,7 +3840,7 @@
 					snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#", p->owner->cid.cid_ani2, p->owner->cid.cid_ani);
 					break;
 				case 1:
-					strncpy(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
+					ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
 					break;
 				case 2:
 					ast_log(LOG_WARNING, "Received unexpected wink on channel of type SIG_FEATDMF_TA\n");
@@ -4787,24 +4775,24 @@
 			tmp->pickupgroup = i->pickupgroup;
 		}
 		if (!ast_strlen_zero(i->language))
-			strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
+			ast_copy_string(tmp->language, i->language, sizeof(tmp->language));
 		if (!ast_strlen_zero(i->musicclass))
-			strncpy(tmp->musicclass, i->musicclass, sizeof(tmp->musicclass)-1);
+			ast_copy_string(tmp->musicclass, i->musicclass, sizeof(tmp->musicclass));
 		if (!i->owner)
 			i->owner = tmp;
 		if (!ast_strlen_zero(i->accountcode))
-			strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
+			ast_copy_string(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode));
 		if (i->amaflags)
 			tmp->amaflags = i->amaflags;
 		i->subs[index].owner = tmp;
-		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
+		ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
 		/* Copy call forward info */
-		strncpy(tmp->call_forward, i->call_forward, sizeof(tmp->call_forward) - 1);
+		ast_copy_string(tmp->call_forward, i->call_forward, sizeof(tmp->call_forward));
 		/* If we've been told "no ADSI" then enforce it */
 		if (!i->adsi)
 			tmp->adsicpe = AST_ADSI_UNAVAILABLE;
 		if (!ast_strlen_zero(i->exten))
-			strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
+			ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
 		if (!ast_strlen_zero(i->rdnis))
 			tmp->cid.cid_rdnis = strdup(i->rdnis);
 		if (!ast_strlen_zero(i->dnid))
@@ -4944,7 +4932,7 @@
 #ifdef ZAPATA_PRI
 	case SIG_PRI:
 		/* Now loop looking for an extension */
-		strncpy(exten, p->exten, sizeof(exten) - 1);
+		ast_copy_string(exten, p->exten, sizeof(exten));
 		len = strlen(exten);
 		res = 0;
 		while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
@@ -4969,7 +4957,7 @@
 		tone_zone_play_tone(p->subs[index].zfd, -1);
 		if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
 			/* Start the real PBX */
-			strncpy(chan->exten, exten, sizeof(chan->exten) - 1);
+			ast_copy_string(chan->exten, exten, sizeof(chan->exten));
 			ast_dsp_digitreset(p->dsp);
 			ast_setstate(chan, AST_STATE_RING);
 			res = ast_pbx_run(chan);
@@ -5060,14 +5048,14 @@
 			ast_hangup(chan);
 			return NULL;
 		}
-		strncpy(exten, dtmfbuf, sizeof(exten)-1);
+		ast_copy_string(exten, dtmfbuf, sizeof(exten));
 		if (ast_strlen_zero(exten))
-			strncpy(exten, "s", sizeof(exten)-1);
+			ast_copy_string(exten, "s", sizeof(exten));
 		if (p->sig == SIG_FEATD || p->sig == SIG_EMWINK) {
 			/* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
 			if (exten[0] == '*') {
 				char *stringp=NULL;
-				strncpy(exten2, exten, sizeof(exten2)-1);
+				ast_copy_string(exten2, exten, sizeof(exten2));
 				/* Parse out extension and callerid */
 				stringp=exten2 +1;
 				s1 = strsep(&stringp, "*");
@@ -5077,16 +5065,16 @@
 						ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
 					else
 						ast_set_callerid(chan, s1, NULL, s1);
-					strncpy(exten, s2, sizeof(exten)-1);
+					ast_copy_string(exten, s2, sizeof(exten));
 				} else
-					strncpy(exten, s1, sizeof(exten)-1);
+					ast_copy_string(exten, s1, sizeof(exten));
 			} else if (p->sig == SIG_FEATD)
 				ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d.  Assuming E&M Wink instead\n", p->channel);
 		}
 		if (p->sig == SIG_FEATDMF) {
 			if (exten[0] == '*') {
 				char *stringp=NULL;
-				strncpy(exten2, exten, sizeof(exten2)-1);
+				ast_copy_string(exten2, exten, sizeof(exten2));
 				/* Parse out extension and callerid */
 				stringp=exten2 +1;
 				s1 = strsep(&stringp, "#");
@@ -5097,16 +5085,16 @@
 					else
 						if(*(s1 + 2))
 							ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
-					strncpy(exten, s2 + 1, sizeof(exten)-1);
+					ast_copy_string(exten, s2 + 1, sizeof(exten));
 				} else
-					strncpy(exten, s1 + 2, sizeof(exten)-1);
+					ast_copy_string(exten, s1 + 2, sizeof(exten));
 			} else
 				ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d.  Assuming E&M Wink instead\n", p->channel);
 		}
 		if (p->sig == SIG_E911) {
 			if (exten[0] == '*') {
 				char *stringp=NULL;
-				strncpy(exten2, exten, sizeof(exten2)-1);
+				ast_copy_string(exten2, exten, sizeof(exten2));
 				/* Parse out extension and callerid */
 				stringp=exten2 +1;
 				s1 = strsep(&stringp, "#");
@@ -5115,8 +5103,8 @@
 					if(*(s2 + 2))
 						ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
 				}
-				if (s1)	strncpy(exten, s1, sizeof(exten)-1);
-				else strncpy(exten, "911", sizeof(exten) - 1);
+				if (s1)	ast_copy_string(exten, s1, sizeof(exten));
+				else ast_copy_string(exten, "911", sizeof(exten));
 				printf("E911: exten: %s, ANI: %s\n",exten, chan->cid.cid_ani);
 			} else
 				ast_log(LOG_WARNING, "Got a non-E911 input on channel %d.  Assuming E&M Wink instead\n", p->channel);
@@ -5124,11 +5112,11 @@
 		if (p->sig == SIG_FEATB) {
 			if (exten[0] == '*') {
 				char *stringp=NULL;
-				strncpy(exten2, exten, sizeof(exten2)-1);
+				ast_copy_string(exten2, exten, sizeof(exten2));
 				/* Parse out extension and callerid */
 				stringp=exten2 +1;
 				s1 = strsep(&stringp, "#");
-				strncpy(exten, exten2 + 1, sizeof(exten)-1);
+				ast_copy_string(exten, exten2 + 1, sizeof(exten));
 			} else
 				ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d.  Assuming E&M Wink instead\n", p->channel);
 		}
@@ -5139,7 +5127,7 @@
 		if ((p->sig == SIG_FEATDMF) || (p->sig == SIG_E911) || (p->sig == SIG_FEATB)) 
 			ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax); 
 		if (ast_exists_extension(chan, chan->context, exten, 1, chan->cid.cid_num)) {
-			strncpy(chan->exten, exten, sizeof(chan->exten)-1);
+			ast_copy_string(chan->exten, exten, sizeof(chan->exten));
 			ast_dsp_digitreset(p->dsp);
 			res = ast_pbx_run(chan);
 			if (res) {
@@ -5198,7 +5186,7 @@
 				if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
 					if (getforward) {
 						/* Record this as the forwarding extension */
-						strncpy(p->call_forward, exten, sizeof(p->call_forward) - 1); 
+						ast_copy_string(p->call_forward, exten, sizeof(p->call_forward)); 
 						if (option_verbose > 2)
 							ast_verbose(VERBOSE_PREFIX_3 "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
 						res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
@@ -5213,7 +5201,7 @@
 						getforward = 0;
 					} else  {
 						res = tone_zone_play_tone(p->subs[index].zfd, -1);
-						strncpy(chan->exten, exten, sizeof(chan->exten)-1);
+						ast_copy_string(chan->exten, exten, sizeof(chan->exten));
 						if (!ast_strlen_zero(p->cid_num)) {
 							if (!p->hidecallerid)
 								ast_set_callerid(chan, p->cid_num, NULL, p->cid_num); 
@@ -5605,8 +5593,8 @@
 						counter1 = 0;
 						/* Check to see if context is what it should be, if not set to be. */
 						if (strcmp(p->context,p->defcontext) != 0) {
-							strncpy(p->context, p->defcontext, sizeof(p->context)-1);
-							strncpy(chan->context,p->defcontext,sizeof(chan->context)-1);
+							ast_copy_string(p->context, p->defcontext, sizeof(p->context));
+							ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
 						}
 		
 						for(;;) {	
@@ -5664,8 +5652,8 @@
 							}
 							if (distMatches == 3) {
 								/* The ring matches, set the context to whatever is for distinctive ring.. */
-								strncpy(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context)-1);
-								strncpy(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context)-1);
+								ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
+								ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
 								if(option_verbose > 2)
 									ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
 								break;
@@ -5707,8 +5695,8 @@
 				counter1 = 0;
 				/* Check to see if context is what it should be, if not set to be. */
 				if (strcmp(p->context,p->defcontext) != 0) {
-					strncpy(p->context, p->defcontext, sizeof(p->context)-1);
-					strncpy(chan->context,p->defcontext,sizeof(chan->context)-1);
+					ast_copy_string(p->context, p->defcontext, sizeof(p->context));
+					ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
 				}
 
 				/* Take out of linear mode for Caller*ID processing */
@@ -5778,8 +5766,8 @@
 						}
 						if (distMatches == 3) {
 							/* The ring matches, set the context to whatever is for distinctive ring.. */
-							strncpy(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context)-1);
-							strncpy(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context)-1);
+							ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
+							ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
 							if(option_verbose > 2)
 								ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
 							break;
@@ -6661,13 +6649,13 @@
 						pris[span].minidle = minidle;
 						pris[span].overlapdial = overlapdial;
 						pris[span].facilityenable = facilityenable;
-						strncpy(pris[span].idledial, idledial, sizeof(pris[span].idledial) - 1);
-						strncpy(pris[span].idleext, idleext, sizeof(pris[span].idleext) - 1);
-						strncpy(pris[span].internationalprefix, internationalprefix, sizeof(pris[span].internationalprefix)-1);
-						strncpy(pris[span].nationalprefix, nationalprefix, sizeof(pris[span].nationalprefix)-1);
-						strncpy(pris[span].localprefix, localprefix, sizeof(pris[span].localprefix)-1);
-						strncpy(pris[span].privateprefix, privateprefix, sizeof(pris[span].privateprefix)-1);
-						strncpy(pris[span].unknownprefix, unknownprefix, sizeof(pris[span].unknownprefix)-1);
+						ast_copy_string(pris[span].idledial, idledial, sizeof(pris[span].idledial));
+						ast_copy_string(pris[span].idleext, idleext, sizeof(pris[span].idleext));
+						ast_copy_string(pris[span].internationalprefix, internationalprefix, sizeof(pris[span].internationalprefix));
+						ast_copy_string(pris[span].nationalprefix, nationalprefix, sizeof(pris[span].nationalprefix));
+						ast_copy_string(pris[span].localprefix, localprefix, sizeof(pris[span].localprefix));
+						ast_copy_string(pris[span].privateprefix, privateprefix, sizeof(pris[span].privateprefix));
+						ast_copy_string(pris[span].unknownprefix, unknownprefix, sizeof(pris[span].unknownprefix));
 						pris[span].resetinterval = resetinterval;
 						
 						tmp->pri = &pris[span];
@@ -6819,7 +6807,7 @@
 			}
 		}
 
-		strncpy(tmp->accountcode, accountcode, sizeof(tmp->accountcode)-1);
+		ast_copy_string(tmp->accountcode, accountcode, sizeof(tmp->accountcode));
 		tmp->amaflags = amaflags;
 		if (!here) {
 			tmp->confno = -1;
@@ -6827,14 +6815,14 @@
 		}
 		tmp->canpark = canpark;
 		tmp->transfer = transfer;
-		strncpy(tmp->defcontext,context,sizeof(tmp->defcontext)-1);
-		strncpy(tmp->language, language, sizeof(tmp->language)-1);
-		strncpy(tmp->musicclass, musicclass, sizeof(tmp->musicclass)-1);
-		strncpy(tmp->context, context, sizeof(tmp->context)-1);
-		strncpy(tmp->cid_num, cid_num, sizeof(tmp->cid_num)-1);
+		ast_copy_string(tmp->defcontext,context,sizeof(tmp->defcontext));
+		ast_copy_string(tmp->language, language, sizeof(tmp->language));
+		ast_copy_string(tmp->musicclass, musicclass, sizeof(tmp->musicclass));
+		ast_copy_string(tmp->context, context, sizeof(tmp->context));
+		ast_copy_string(tmp->cid_num, cid_num, sizeof(tmp->cid_num));
 		tmp->cid_ton = 0;
-		strncpy(tmp->cid_name, cid_name, sizeof(tmp->cid_name)-1);
-		strncpy(tmp->mailbox, mailbox, sizeof(tmp->mailbox)-1);
+		ast_copy_string(tmp->cid_name, cid_name, sizeof(tmp->cid_name));
+		ast_copy_string(tmp->mailbox, mailbox, sizeof(tmp->mailbox));
 		tmp->msgstate = -1;
 		tmp->group = cur_group;
 		tmp->callgroup=cur_callergroup;
@@ -7443,8 +7431,8 @@
 			switch(f->subclass) {
 			case AST_CONTROL_ANSWER:
 				/* Launch the PBX */
-				strncpy(chan->exten, pvt->pri->idleext, sizeof(chan->exten) - 1);
-				strncpy(chan->context, pvt->pri->idlecontext, sizeof(chan->context) - 1);
+				ast_copy_string(chan->exten, pvt->pri->idleext, sizeof(chan->exten));
+				ast_copy_string(chan->context, pvt->pri->idlecontext, sizeof(chan->context));
 				chan->priority = 1;
 				if (option_verbose > 3) 
 					ast_verbose(VERBOSE_PREFIX_3 "Idle channel '%s' answered, sending to %s@%s\n", chan->name, chan->exten, chan->context);
@@ -7581,7 +7569,7 @@
 		if (cc) {
 			*cc = '\0';
 			cc++;
-			strncpy(pri->idlecontext, cc, sizeof(pri->idlecontext) - 1);
+			ast_copy_string(pri->idlecontext, cc, sizeof(pri->idlecontext));
 #if 0
 			/* Extensions may not be loaded yet */
 			if (!ast_exists_extension(NULL, pri->idlecontext, pri->idleext, 1, NULL))
@@ -7965,15 +7953,15 @@
 					}
 					if (pri->pvts[chanpos]->use_callerid) {
 						ast_shrink_phone_number(plancallingnum);
-						strncpy(pri->pvts[chanpos]->cid_num, plancallingnum, sizeof(pri->pvts[chanpos]->cid_num)-1);
-						strncpy(pri->pvts[chanpos]->cid_name, e->ring.callingname, sizeof(pri->pvts[chanpos]->cid_name)-1);
+						ast_copy_string(pri->pvts[chanpos]->cid_num, plancallingnum, sizeof(pri->pvts[chanpos]->cid_num));
+						ast_copy_string(pri->pvts[chanpos]->cid_name, e->ring.callingname, sizeof(pri->pvts[chanpos]->cid_name));
 						pri->pvts[chanpos]->cid_ton = e->ring.callingplan; /* this is the callingplan (TON/NPI), e->ring.callingplan>>4 would be the TON */
 					} else {
 						pri->pvts[chanpos]->cid_num[0] = '\0';
 						pri->pvts[chanpos]->cid_name[0] = '\0';
 						pri->pvts[chanpos]->cid_ton = 0;
 					}
-					strncpy(pri->pvts[chanpos]->rdnis, e->ring.redirectingnum, sizeof(pri->pvts[chanpos]->rdnis) - 1);
+					ast_copy_string(pri->pvts[chanpos]->rdnis, e->ring.redirectingnum, sizeof(pri->pvts[chanpos]->rdnis));
 					/* If immediate=yes go to s|1 */
 					if (pri->pvts[chanpos]->immediate) {
 						if (option_verbose > 2)
@@ -7983,13 +7971,13 @@
 					}
 					/* Get called number */
 					else if (!ast_strlen_zero(e->ring.callednum)) {
-						strncpy(pri->pvts[chanpos]->exten, e->ring.callednum, sizeof(pri->pvts[chanpos]->exten)-1);
-						strncpy(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid) - 1);
+						ast_copy_string(pri->pvts[chanpos]->exten, e->ring.callednum, sizeof(pri->pvts[chanpos]->exten));
+						ast_copy_string(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid));
 					} else
 						pri->pvts[chanpos]->exten[0] = '\0';
 					/* Set DNID on all incoming calls -- even immediate */
 					if (!ast_strlen_zero(e->ring.callednum))
-						strncpy(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid) - 1);
+						ast_copy_string(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid));
 					/* No number yet, but received "sending complete"? */
 					if (e->ring.complete && (ast_strlen_zero(e->ring.callednum))) {
 						if (option_verbose > 2)
@@ -8246,8 +8234,8 @@
 					} else {
 						/* Re-use *69 field for PRI */
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
-						strncpy(pri->pvts[chanpos]->lastcid_num, e->facname.callingnum, sizeof(pri->pvts[chanpos]->lastcid_num) - 1);
-						strncpy(pri->pvts[chanpos]->lastcid_name, e->facname.callingname, sizeof(pri->pvts[chanpos]->lastcid_name) - 1);
+						ast_copy_string(pri->pvts[chanpos]->lastcid_num, e->facname.callingnum, sizeof(pri->pvts[chanpos]->lastcid_num));
+						ast_copy_string(pri->pvts[chanpos]->lastcid_name, e->facname.callingname, sizeof(pri->pvts[chanpos]->lastcid_name));
 						pri->pvts[chanpos]->subs[SUB_REAL].needcallerid =1;
 						zt_enable_ec(pri->pvts[chanpos]);
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
@@ -8694,7 +8682,7 @@
 			close(pridebugfd);
 
 		pridebugfd = myfd;
-		strncpy(pridebugfilename,argv[4],sizeof(pridebugfilename)-1);
+		ast_copy_string(pridebugfilename,argv[4],sizeof(pridebugfilename));
 		
 		ast_mutex_unlock(&pridebugfdlock);
 
@@ -9065,7 +9053,7 @@
 		if (tmp->channel > 0) {
 			snprintf(tmps, sizeof(tmps), "%d", tmp->channel);
 		} else
-			strncpy(tmps, "pseudo", sizeof(tmps) - 1);
+			ast_copy_string(tmps, "pseudo", sizeof(tmps));
 		ast_cli(fd, FORMAT, tmps, tmp->exten, tmp->context, tmp->language, tmp->musicclass);
 		tmp = tmp->next;
 	}
@@ -9753,11 +9741,11 @@
 			if (ast_true(v->value))
 				usedistinctiveringdetection = 1;
 		} else if (!strcasecmp(v->name, "dring1context")) {
-			strncpy(drings.ringContext[0].contextData,v->value,sizeof(drings.ringContext[0].contextData)-1);
+			ast_copy_string(drings.ringContext[0].contextData,v->value,sizeof(drings.ringContext[0].contextData));
 		} else if (!strcasecmp(v->name, "dring2context")) {
-			strncpy(drings.ringContext[1].contextData,v->value,sizeof(drings.ringContext[1].contextData)-1);
+			ast_copy_string(drings.ringContext[1].contextData,v->value,sizeof(drings.ringContext[1].contextData));
 		} else if (!strcasecmp(v->name, "dring3context")) {
-			strncpy(drings.ringContext[2].contextData,v->value,sizeof(drings.ringContext[2].contextData)-1);
+			ast_copy_string(drings.ringContext[2].contextData,v->value,sizeof(drings.ringContext[2].contextData));
 		} else if (!strcasecmp(v->name, "dring1")) {
 			ringc = v->value;
 			sscanf(ringc, "%d,%d,%d", &drings.ringnum[0].ring[0], &drings.ringnum[0].ring[1], &drings.ringnum[0].ring[2]);
@@ -9795,7 +9783,7 @@
 			else
 				relaxdtmf = 0;
 		} else if (!strcasecmp(v->name, "mailbox")) {
-			strncpy(mailbox, v->value, sizeof(mailbox) -1);
+			ast_copy_string(mailbox, v->value, sizeof(mailbox));
 		} else if (!strcasecmp(v->name, "adsi")) {
 			adsi = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "transfer")) {
@@ -9858,13 +9846,13 @@
 		} else if (!strcasecmp(v->name, "callwaitingcallerid")) {
 			callwaitingcallerid = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "context")) {
-			strncpy(context, v->value, sizeof(context)-1);
+			ast_copy_string(context, v->value, sizeof(context));
 		} else if (!strcasecmp(v->name, "language")) {
-			strncpy(language, v->value, sizeof(language)-1);
+			ast_copy_string(language, v->value, sizeof(language));
 		} else if (!strcasecmp(v->name, "progzone")) {
-			strncpy(progzone, v->value, sizeof(progzone)-1);
+			ast_copy_string(progzone, v->value, sizeof(progzone));
 		} else if (!strcasecmp(v->name, "musiconhold")) {
-			strncpy(musicclass, v->value, sizeof(musicclass)-1);
+			ast_copy_string(musicclass, v->value, sizeof(musicclass));
 		} else if (!strcasecmp(v->name, "stripmsd")) {
 			stripmsd = atoi(v->value);
 		} else if (!strcasecmp(v->name, "jitterbuffers")) {
@@ -9903,7 +9891,7 @@
 		} else if (!strcasecmp(v->name, "usecallingpres")) {
 			use_callingpres = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "accountcode")) {
-			strncpy(accountcode, v->value, sizeof(accountcode)-1);
+			ast_copy_string(accountcode, v->value, sizeof(accountcode));
 		} else if (!strcasecmp(v->name, "amaflags")) {
 			y = ast_cdr_amaflags2int(v->value);
 			if (y < 0) 
@@ -10115,15 +10103,15 @@
 					ast_log(LOG_WARNING, "'%s' is not a valid pri indication value, should be 'inband' or 'outofband' at line %d\n",
 						v->value, v->lineno);
 			} else if (!strcasecmp(v->name, "internationalprefix")) {
-				strncpy(internationalprefix, v->value, sizeof(internationalprefix)-1);
+				ast_copy_string(internationalprefix, v->value, sizeof(internationalprefix));
 			} else if (!strcasecmp(v->name, "nationalprefix")) {
-				strncpy(nationalprefix, v->value, sizeof(nationalprefix)-1);
+				ast_copy_string(nationalprefix, v->value, sizeof(nationalprefix));
 			} else if (!strcasecmp(v->name, "localprefix")) {
-				strncpy(localprefix, v->value, sizeof(localprefix)-1);
+				ast_copy_string(localprefix, v->value, sizeof(localprefix));
 			} else if (!strcasecmp(v->name, "privateprefix")) {
-				strncpy(privateprefix, v->value, sizeof(privateprefix)-1);
+				ast_copy_string(privateprefix, v->value, sizeof(privateprefix));
 			} else if (!strcasecmp(v->name, "unknownprefix")) {
-				strncpy(unknownprefix, v->value, sizeof(unknownprefix)-1);
+				ast_copy_string(unknownprefix, v->value, sizeof(unknownprefix));
 			} else if (!strcasecmp(v->name, "resetinterval")) {
 				if (!strcasecmp(v->value, "never"))
 					resetinterval = -1;
@@ -10135,9 +10123,9 @@
 			} else if (!strcasecmp(v->name, "minunused")) {
 				minunused = atoi(v->value);
 			} else if (!strcasecmp(v->name, "idleext")) {
-				strncpy(idleext, v->value, sizeof(idleext) - 1);
+				ast_copy_string(idleext, v->value, sizeof(idleext));
 			} else if (!strcasecmp(v->name, "idledial")) {
-				strncpy(idledial, v->value, sizeof(idledial) - 1);
+				ast_copy_string(idledial, v->value, sizeof(idledial));
 			} else if (!strcasecmp(v->name, "overlapdial")) {
 				overlapdial = ast_true(v->value);
 			} else if (!strcasecmp(v->name, "pritimer")) {
@@ -10173,7 +10161,7 @@
 				char original_args[80];
 				int cadence_is_ok = 1;
 
-				strncpy(original_args, v->value, sizeof(original_args) - 1);
+				ast_copy_string(original_args, v->value, sizeof(original_args));
 				/* 16 cadences allowed (8 pairs) */
 				element_count = sscanf(v->value, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12], &c[13], &c[14], &c[15]);
 	
@@ -10271,9 +10259,9 @@
 			} else if (!strcasecmp(v->name, "sendcalleridafter")) {
 				sendcalleridafter = atoi(v->value);
 			} else if (!strcasecmp(v->name, "defaultcic")) {
-				strncpy(defaultcic, v->value, sizeof(defaultcic));
+				ast_copy_string(defaultcic, v->value, sizeof(defaultcic));
 			} else if (!strcasecmp(v->name, "defaultozz")) {
-				strncpy(defaultozz, v->value, sizeof(defaultozz));
+				ast_copy_string(defaultozz, v->value, sizeof(defaultozz));
 			} 
 		} else 
 			ast_log(LOG_WARNING, "Ignoring %s\n", v->name);




More information about the svn-commits mailing list