[xiph-commits] r14184 - trunk/ao/src/plugins/nas

ivo at svn.xiph.org ivo at svn.xiph.org
Sun Nov 18 19:22:12 PST 2007


Author: ivo
Date: 2007-11-18 19:22:11 -0800 (Sun, 18 Nov 2007)
New Revision: 14184

Modified:
   trunk/ao/src/plugins/nas/ao_nas.c
Log:
fixes for segmentation fault caused by integer overflow and improvements to buffer handling using patch in ticket #665

Modified: trunk/ao/src/plugins/nas/ao_nas.c
===================================================================
--- trunk/ao/src/plugins/nas/ao_nas.c	2007-11-18 16:07:51 UTC (rev 14183)
+++ trunk/ao/src/plugins/nas/ao_nas.c	2007-11-19 03:22:11 UTC (rev 14184)
@@ -34,6 +34,10 @@
 #include <ao/ao.h>
 #include <ao/plugin.h>
 
+/*
+* Buffer size must be greater than 2.
+*/
+
 #define AO_NAS_BUF_SIZE 4096
 
 static char *ao_nas_options[] = {
@@ -61,8 +65,8 @@
   AuFlowID flow;
   AuDeviceID dev;
   char *host;
-  int buf_size;
-  int buf_free;
+  AuUint32 buf_size;
+  AuUint32 buf_free;
 } ao_nas_internal;
 
 int ao_plugin_test()
@@ -96,7 +100,7 @@
 	
 	internal->host = NULL;
 	internal->buf_size = AO_NAS_BUF_SIZE;
-	internal->buf_free = -1;
+	internal->buf_free = 0;
 
 	device->internal = internal;
 	return 1; /* Memory alloc successful */
@@ -107,18 +111,17 @@
 	ao_nas_internal *internal = (ao_nas_internal *) device->internal;
 
 	if (!strcmp(key, "host")) {
-	  if (internal->host)
-	    free(internal->host);
-	  internal->host = strdup(value);
-	  if (!internal->host)
-	    return 0;
+          char *tmp = strdup (value);
+ 	  if (!tmp) return 0;
+ 	  if (internal->host) free (internal->host);
+ 	  internal->host = tmp;
 	}
 	else if (!strcmp(key, "buf_size")) {
-	  internal->buf_size = atoi(value);
-	  if (internal->buf_size <= 2)
-	    return 0;
+          int tmp = atoi (value);
+ 	  if (tmp <= 2) return 0;
+ 	  internal->buf_size = tmp;
 	}
-		 
+
 	return 1;
 }
 
@@ -189,7 +192,7 @@
 
 	while (num_bytes > 0) {
 	  /* Wait for room in buffer */
-	  while (internal->buf_free <= 0) {
+	  while (internal->buf_free == 0) {
 	    AuEvent ev;
 	    AuNextEvent(internal->aud, AuTrue, &ev);
 	    if (ev.type == AuEventTypeElementNotify) {
@@ -202,11 +205,11 @@
 		internal->buf_free = event->num_bytes;
 	    }
 	  }
-	  
+
 	  /* Partial transfer */
 	  if (num_bytes > internal->buf_free) {
 	    AuWriteElement(internal->aud, internal->flow, 0, internal->buf_free,
-			   output_samples, AuFalse, 0);
+			   (AuPointer)output_samples, AuFalse, 0);
 	    num_bytes -= internal->buf_free;
 	    output_samples += internal->buf_free;
 	    internal->buf_free = 0;
@@ -215,7 +218,7 @@
 	  /* Final transfer */
 	  else {
 	    AuWriteElement(internal->aud, internal->flow, 0, num_bytes,
-			   output_samples, AuFalse, 0);
+			   (AuPointer)output_samples, AuFalse, 0);
 	    internal->buf_free -= num_bytes;
 	    break;
 	  }
@@ -241,4 +244,4 @@
 
 	free(internal->host);
 	free(internal);
-}
+}
\ No newline at end of file



More information about the commits mailing list