summaryrefslogtreecommitdiff
path: root/devel/cvsps/patches/patch-ab
blob: b02f39a3fd3a9199340d9eead90800902009a8c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$NetBSD: patch-ab,v 1.2 2009/08/30 17:16:54 schmonz Exp $

--- cvsps.c.orig	2009-08-30 13:07:32.000000000 -0400
+++ cvsps.c
@@ -265,7 +265,8 @@ static void load_from_cvs()
     PatchSetMember * psm = NULL;
     char datebuff[20];
     char authbuff[AUTH_STR_MAX];
-    char logbuff[LOG_STR_MAX + 1];
+    int logbufflen = LOG_STR_MAX + 1;
+    char * logbuff = malloc(logbufflen);
     int loglen = 0;
     int have_log = 0;
     char cmd[BUFSIZ];
@@ -273,6 +274,12 @@ static void load_from_cvs()
     char use_rep_buff[PATH_MAX];
     char * ltype;
 
+    if (logbuff == NULL)
+    {
+	debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in load_from_cvs", logbufflen);
+	exit(1);
+    }
+
     if (!no_rlog && !test_log_file && cvs_check_cap(CAP_HAVE_RLOG))
     {
 	ltype = "rlog";
@@ -480,24 +487,22 @@ static void load_from_cvs()
 		 */
 		if (have_log || !is_revision_metadata(buff))
 		{
-		    /* if the log buffer is full, that's it.  
-		     * 
-		     * Also, read lines (fgets) always have \n in them
-		     * which we count on.  So if truncation happens,
-		     * be careful to put a \n on.
-		     * 
-		     * Buffer has LOG_STR_MAX + 1 for room for \0 if
-		     * necessary
-		     */
-		    if (loglen < LOG_STR_MAX)
+		    /* If the log buffer is full, try to reallocate more. */
+		    if (loglen < logbufflen)
 		    {
 			int len = strlen(buff);
 			
-			if (len >= LOG_STR_MAX - loglen)
+			if (len >= logbufflen - loglen)
 			{
-			    debug(DEBUG_APPMSG1, "WARNING: maximum log length exceeded, truncating log");
-			    len = LOG_STR_MAX - loglen;
-			    buff[len - 1] = '\n';
+			    debug(DEBUG_STATUS, "reallocating logbufflen to %d bytes for file %s", logbufflen, file->filename);
+			    logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
+			    char * newlogbuff = realloc(logbuff, logbufflen);
+			    if (newlogbuff == NULL)
+			    {
+				debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in load_from_cvs", logbufflen);
+				exit(1);
+			    }
+			    logbuff = newlogbuff;
 			}
 
 			debug(DEBUG_STATUS, "appending %s to log", buff);