summaryrefslogtreecommitdiff
path: root/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/cache.c b/cache.c
index 4c51cf7..01a8ed3 100644
--- a/cache.c
+++ b/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;
}