[35279] trunk/base/src/pextlib1.0/tracelib.c

epimenov at macports.org epimenov at macports.org
Sun Mar 23 13:46:34 PDT 2008


Revision: 35279
          http://trac.macosforge.org/projects/macports/changeset/35279
Author:   epimenov at macports.org
Date:     2008-03-23 13:46:32 -0700 (Sun, 23 Mar 2008)

Log Message:
-----------
Tracelib

1) I allow /Developer, not only /Developer/Headers. Because Xcode 3.1 (aka iPhone SDK) uses a lot of stuff here. It can't compile without /Developer/Platform/MacOSX.platform for example. Also SDK redirection will not work with Xcode 3.1. Also it introduce ablitity to change /Developer folder, so we should handle this somehow.
2) Also this commit fixes issue with recv overflow. If you run xcodebuild with old rules you'll see a lot of sandbox viloations (xcode scans for plugins, platforms and so on), and you'll see malformed commands. It happens when tracelib sends more than 1024 bytes of data. Now it properly handled.

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/tracelib.c

Modified: trunk/base/src/pextlib1.0/tracelib.c
===================================================================
--- trunk/base/src/pextlib1.0/tracelib.c	2008-03-23 19:44:07 UTC (rev 35278)
+++ trunk/base/src/pextlib1.0/tracelib.c	2008-03-23 20:46:32 UTC (rev 35279)
@@ -123,21 +123,56 @@
 }
 
 /*
+ * Is there more data? (return 1 if more data in socket, 0 otherwise)
+ */
+static char can_I_recv_more(int sock)
+{
+	struct timeval tv;
+	fd_set fdr;
+	tv.tv_sec  = 0;
+	tv.tv_usec = 0;
+
+	FD_ZERO(&fdr);
+	FD_SET(sock, &fdr);
+	return select(sock+1, &fdr, 0, 0, &tv) == 1;
+}
+
+/*
  * receive line from socket, parse it and send answer
  */
 static char process_line(int sock)
 {
-	char * t, buf[1024]={0}, *f;
+	char * t, buf[1024]={0}, *f, *next_t;
 	int len;
 	
-	if((len=recv(sock, buf, sizeof(buf), 0))==-1)
+	if((len=recv(sock, buf, sizeof(buf) - 1, 0))==-1)
 		return 0;
 	if(!len)
 		return 0;
 	buf[len]=0;
-	/* sometimes two messages come in one recv.. I ain't caring about it now, but it can be a problem */
-	for(t=buf;*t&&t-buf<(int)sizeof(buf);t=f+strlen(f)+1)
+	for(t=buf;*t&&t-buf<(int)sizeof(buf);t=next_t)
 	{
+		next_t = t+strlen(t)+1;
+		if(next_t == buf + sizeof(buf) && len == sizeof(buf) - 1)
+		{
+			memmove(buf, t, next_t - t);
+			t = buf;
+			{
+				char * end_of_t = t + strlen(t);
+				*end_of_t = ' ';
+				for(;can_I_recv_more(sock);)
+				{
+					if(recv(sock, end_of_t, 1, 0) != 1)
+					{
+						ui_warn("recv failed");
+						return 0;
+					}
+					if(*end_of_t++ == 0)
+						break;
+				}
+			}
+		}
+    
 		f=strchr(t, '\t');
 		if(!f)
 		{
@@ -145,6 +180,7 @@
 			break;
 		}
 		*f++=0;
+
 		if(!strcmp(t, "filemap"))
 		{
 			send_file_map(sock);
@@ -206,7 +242,7 @@
 				append_allow("/usr", 0);
 				append_allow("/System/Library", 0);
 				append_allow("/Library", 0);
-				append_allow("/Developer/Headers", 0);
+				append_allow("/Developer", 0);
 			}
 		}else
 			append_allow("/", 0);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080323/db657a5d/attachment.html 


More information about the macports-changes mailing list