summaryrefslogtreecommitdiff
path: root/devel/cvsps/patches/patch-ac
blob: 7977987f23de0db78844d45beb733bcb83f340d3 (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
$NetBSD: patch-ac,v 1.1 2009/08/30 17:16:54 schmonz Exp $

--- cache.c.orig	2005-05-25 23:39:40.000000000 -0400
+++ cache.c
@@ -108,10 +108,19 @@ time_t read_cache()
     int tag_flags = 0;
     char branchbuff[LOG_STR_MAX] = "";
     int branch_add = 0;
-    char logbuff[LOG_STR_MAX] = "";
+    int logbufflen = LOG_STR_MAX + 1;
+    char * logbuff = malloc(logbufflen);
     time_t cache_date = -1;
     int read_version;
 
+    if (logbuff == NULL)
+    {
+	debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in read_cache", logbufflen);
+	exit(1);
+    }
+
+    logbuff[0] = 0;
+
     if (!(fp = cache_open("r")))
 	goto out;
 
@@ -299,8 +308,19 @@ time_t read_cache()
 	    else
 	    {
 		/* Make sure we have enough in the buffer */
-		if (strlen(logbuff)+strlen(buff)<LOG_STR_MAX)
-		    strcat(logbuff, buff);
+		int len = strlen(buff);
+		if (strlen(logbuff) + len >= LOG_STR_MAX)
+		{
+		    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 read_cache", logbufflen);
+			exit(1);
+		    }
+		    logbuff = newlogbuff;
+		}
+		strcat(logbuff, buff);
 	    }
 	    break;
 	case CACHE_NEED_PS_MEMBERS:
@@ -332,6 +352,7 @@ time_t read_cache()
  out_close:
     fclose(fp);
  out:
+    free(logbuff);
     return cache_date;
 }