[asterisk-commits] tilghman: branch 1.6.1 r182280 - in /branches/1.6.1: ./ channels/ funcs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 16 12:38:55 CDT 2009


Author: tilghman
Date: Mon Mar 16 12:38:50 2009
New Revision: 182280

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=182280
Log:
Merged revisions 182211,182278 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r182211 | tilghman | 2009-03-16 10:50:55 -0500 (Mon, 16 Mar 2009) | 14 lines
  
  Merged revisions 182208 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r182208 | tilghman | 2009-03-16 10:39:15 -0500 (Mon, 16 Mar 2009) | 7 lines
    
    Fixup glare detection, to fix a memory leak of a local pvt structure.
    (closes issue #14656)
     Reported by: caspy
     Patches: 
           20090313__bug14656__2.diff.txt uploaded by tilghman (license 14)
     Tested by: caspy
  ........
................
  r182278 | tilghman | 2009-03-16 12:33:38 -0500 (Mon, 16 Mar 2009) | 7 lines
  
  Fix an off-by-one error in the FILE() function, and extend FILE()'s length parameter to work like variable substitution.
  Previously, FILE() returned one less character than specified, due to the
  terminating NULL.  Both the offset and length parameters now behave
  identically to the way variable substitution offsets and lengths also work.
  (closes issue #14670)
   Reported by: BMC
................

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/channels/chan_local.c
    branches/1.6.1/funcs/func_env.c

Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/channels/chan_local.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/channels/chan_local.c?view=diff&rev=182280&r1=182279&r2=182280
==============================================================================
--- branches/1.6.1/channels/chan_local.c (original)
+++ branches/1.6.1/channels/chan_local.c Mon Mar 16 12:38:50 2009
@@ -203,23 +203,17 @@
 	/* Recalculate outbound channel */
 	other = isoutbound ? p->owner : p->chan;
 
+	if (!other) {
+		return 0;
+	}
+
+	/* do not queue frame if generator is on both local channels */
+	if (us && us->generator && other->generator) {
+		return 0;
+	}
+
 	/* Set glare detection */
 	ast_set_flag(p, LOCAL_GLARE_DETECT);
-	if (ast_test_flag(p, LOCAL_CANCEL_QUEUE)) {
-		/* We had a glare on the hangup.  Forget all this business,
-		return and destroy p.  */
-		ast_mutex_unlock(&p->lock);
-		p = local_pvt_destroy(p);
-		return -1;
-	}
-	if (!other) {
-		ast_clear_flag(p, LOCAL_GLARE_DETECT);
-		return 0;
-	}
-
-	/* do not queue frame if generator is on both local channels */
-	if (us && us->generator && other->generator)
-		return 0;
 
 	/* Ensure that we have both channels locked */
 	while (other && ast_channel_trylock(other)) {
@@ -233,6 +227,17 @@
 			ast_mutex_lock(&p->lock);
 		}
 		other = isoutbound ? p->owner : p->chan;
+	}
+
+	/* Since glare detection only occurs within this function, and because
+	 * a pvt flag cannot be set without having the pvt lock, this is the only
+	 * location where we could detect a cancelling of the queue. */
+	if (ast_test_flag(p, LOCAL_CANCEL_QUEUE)) {
+		/* We had a glare on the hangup.  Forget all this business,
+		return and destroy p.  */
+		ast_mutex_unlock(&p->lock);
+		p = local_pvt_destroy(p);
+		return -1;
 	}
 
 	if (other) {

Modified: branches/1.6.1/funcs/func_env.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/funcs/func_env.c?view=diff&rev=182280&r1=182279&r2=182280
==============================================================================
--- branches/1.6.1/funcs/func_env.c (original)
+++ branches/1.6.1/funcs/func_env.c Mon Mar 16 12:38:50 2009
@@ -113,40 +113,59 @@
 		AST_APP_ARG(offset);
 		AST_APP_ARG(length);
 	);
-	int offset = 0, length;
+	int offset = 0, length, res = 0;
 	char *contents;
+	size_t contents_len;
 
 	AST_STANDARD_APP_ARGS(args, data);
-	if (args.argc > 1)
+	if (args.argc > 1) {
 		offset = atoi(args.offset);
+	}
 
 	if (args.argc > 2) {
-		if ((length = atoi(args.length)) < 1) {
-			ast_log(LOG_WARNING, "Invalid length '%s'.  Returning the max (%d)\n", args.length, (int)len);
+		/* The +1/-1 in this code section is to accomodate for the terminating NULL. */
+		if ((length = atoi(args.length) + 1) > len) {
+			ast_log(LOG_WARNING, "Length %d is greater than the max (%d).  Truncating output.\n", length - 1, (int)len - 1);
 			length = len;
-		} else if (length > len) {
-			ast_log(LOG_WARNING, "Length %d is greater than the max (%d).  Truncating output.\n", length, (int)len);
-			length = len;
-		}
-	} else
+		}
+	} else {
 		length = len;
-
-	if (!(contents = ast_read_textfile(args.filename)))
+	}
+
+	if (!(contents = ast_read_textfile(args.filename))) {
 		return -1;
-
-	if (offset >= 0)
-		ast_copy_string(buf, &contents[offset], length);
-	else {
-		size_t tmp = strlen(contents);
-		if (offset * -1 > tmp) {
-			ast_log(LOG_WARNING, "Offset is larger than the file size.\n");
-			offset = tmp * -1;
-		}
-		ast_copy_string(buf, &contents[tmp + offset], length);
-	}
+	}
+
+	do {
+		contents_len = strlen(contents);
+		if (offset > contents_len) {
+			res = -1;
+			break;
+		}
+
+		if (offset >= 0) {
+			if (length < 0) {
+				if (contents_len - offset + length < 0) {
+					/* Nothing left after trimming */
+					res = -1;
+					break;
+				}
+				ast_copy_string(buf, &contents[offset], contents_len + length);
+			} else {
+				ast_copy_string(buf, &contents[offset], length);
+			}
+		} else {
+			if (offset * -1 > contents_len) {
+				ast_log(LOG_WARNING, "Offset is larger than the file size.\n");
+				offset = contents_len * -1;
+			}
+			ast_copy_string(buf, &contents[contents_len + offset], length);
+		}
+	} while (0);
+
 	ast_free(contents);
 
-	return 0;
+	return res;
 }
 
 static struct ast_custom_function env_function = {




More information about the asterisk-commits mailing list