Blame SOURCES/cvsps-2.2b1-dynamic-logbuf.patch

fc0301
# From: http://ydirson.free.fr/soft/git/cvsps.git
fc0301
fc0301
commit 76a9c2aaa0d2957de0bc8f0c0b994abfd1645a50
fc0301
Author: David D. Kilzer <ddkilzer@kilzer.net>
fc0301
Date:   Mon Jun 20 01:04:34 2005 +0200
fc0301
fc0301
    Dynamically allocate the log buffer to prevent warning messages
fc0301
    
fc0301
    On anoncvs.opensource.apple.com (Apple's anonymous CVS server for
fc0301
    WebKit), some very long log entries were included in CVS.  I got tired
fc0301
    of cvsps-2.1 truncating them, so I made the 'logbuff' buffer be
fc0301
    dynamically allocated.
fc0301
fc0301
diff --git i/cache.c w/cache.c
fc0301
index 4c51cf7..01a8ed3 100644
fc0301
--- i/cache.c
fc0301
+++ w/cache.c
fc0301
@@ -108,10 +108,19 @@ time_t read_cache()
fc0301
     int tag_flags = 0;
fc0301
     char branchbuff[LOG_STR_MAX] = "";
fc0301
     int branch_add = 0;
fc0301
-    char logbuff[LOG_STR_MAX] = "";
fc0301
+    int logbufflen = LOG_STR_MAX + 1;
fc0301
+    char * logbuff = malloc(logbufflen);
fc0301
     time_t cache_date = -1;
fc0301
     int read_version;
fc0301
 
fc0301
+    if (logbuff == NULL)
fc0301
+    {
fc0301
+	debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in read_cache", logbufflen);
fc0301
+	exit(1);
fc0301
+    }
fc0301
+
fc0301
+    logbuff[0] = 0;
fc0301
+
fc0301
     if (!(fp = cache_open("r")))
fc0301
 	goto out;
fc0301
 
fc0301
@@ -299,8 +308,19 @@ time_t read_cache()
fc0301
 	    else
fc0301
 	    {
fc0301
 		/* Make sure we have enough in the buffer */
fc0301
-		if (strlen(logbuff)+strlen(buff)
fc0301
-		    strcat(logbuff, buff);
fc0301
+		int len = strlen(buff);
fc0301
+		if (strlen(logbuff) + len >= LOG_STR_MAX)
fc0301
+		{
fc0301
+		    logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
fc0301
+		    char * newlogbuff = realloc(logbuff, logbufflen);
fc0301
+		    if (newlogbuff == NULL)
fc0301
+		    {
fc0301
+			debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in read_cache", logbufflen);
fc0301
+			exit(1);
fc0301
+		    }
fc0301
+		    logbuff = newlogbuff;
fc0301
+		}
fc0301
+		strcat(logbuff, buff);
fc0301
 	    }
fc0301
 	    break;
fc0301
 	case CACHE_NEED_PS_MEMBERS:
fc0301
@@ -332,6 +352,7 @@ time_t read_cache()
fc0301
  out_close:
fc0301
     fclose(fp);
fc0301
  out:
fc0301
+    free(logbuff);
fc0301
     return cache_date;
fc0301
 }
fc0301
 
fc0301
diff --git i/cvsps.c w/cvsps.c
fc0301
index f0e7d29..db28d7c 100644
fc0301
--- i/cvsps.c
fc0301
+++ w/cvsps.c
fc0301
@@ -269,7 +269,8 @@ static void load_from_cvs()
fc0301
     PatchSetMember * psm = NULL;
fc0301
     char datebuff[26];
fc0301
     char authbuff[AUTH_STR_MAX];
fc0301
-    char logbuff[LOG_STR_MAX + 1];
fc0301
+    int logbufflen = LOG_STR_MAX + 1;
fc0301
+    char * logbuff = malloc(logbufflen);
fc0301
     int loglen = 0;
fc0301
     int have_log = 0;
fc0301
     char cmd[BUFSIZ];
fc0301
@@ -277,6 +278,12 @@ static void load_from_cvs()
fc0301
     char use_rep_buff[PATH_MAX];
fc0301
     char * ltype;
fc0301
 
fc0301
+    if (logbuff == NULL)
fc0301
+    {
fc0301
+	debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in load_from_cvs", logbufflen);
fc0301
+	exit(1);
fc0301
+    }
fc0301
+
fc0301
     if (!no_rlog && !test_log_file && cvs_check_cap(CAP_HAVE_RLOG))
fc0301
     {
fc0301
 	ltype = "rlog";
fc0301
@@ -484,25 +491,22 @@ static void load_from_cvs()
fc0301
 		 */
fc0301
 		if (have_log || !is_revision_metadata(buff))
fc0301
 		{
fc0301
-		    /* if the log buffer is full, that's it.  
fc0301
-		     * 
fc0301
-		     * Also, read lines (fgets) always have \n in them
fc0301
-		     * (unless truncation happens)
fc0301
-		     * which we count on.  So if truncation happens,
fc0301
-		     * be careful to put a \n on.
fc0301
-		     * 
fc0301
-		     * Buffer has LOG_STR_MAX + 1 for room for \0 if
fc0301
-		     * necessary
fc0301
-		     */
fc0301
-		    if (loglen < LOG_STR_MAX)
fc0301
+		    /* If the log buffer is full, try to reallocate more. */
fc0301
+		    if (loglen < logbufflen)
fc0301
 		    {
fc0301
 			int len = strlen(buff);
fc0301
 			
fc0301
-			if (len >= LOG_STR_MAX - loglen)
fc0301
+			if (len >= logbufflen - loglen)
fc0301
 			{
fc0301
-			    debug(DEBUG_APPMSG1, "WARNING: maximum log length exceeded, truncating log");
fc0301
-			    len = LOG_STR_MAX - loglen;
fc0301
-			    buff[len - 1] = '\n';
fc0301
+			    debug(DEBUG_STATUS, "reallocating logbufflen to %d bytes for file %s", logbufflen, file->filename);
fc0301
+			    logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
fc0301
+			    char * newlogbuff = realloc(logbuff, logbufflen);
fc0301
+			    if (newlogbuff == NULL)
fc0301
+			    {
fc0301
+				debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in load_from_cvs", logbufflen);
fc0301
+				exit(1);
fc0301
+			    }
fc0301
+			    logbuff = newlogbuff;
fc0301
 			}
fc0301
 
fc0301
 			debug(DEBUG_STATUS, "appending %s to log", buff);