aboutsummaryrefslogtreecommitdiffstats
path: root/cache.c
diff options
context:
space:
mode:
authorLars Hjemli2007-05-18 03:54:15 +0200
committerLars Hjemli2007-05-18 22:51:02 +0200
commit72fa5c63f80262019d807658cc537c9897c4b1d1 (patch)
treedd10f33b94e95574a145ddd7e82b22356039f3a0 /cache.c
parent30ccdcaa74ebc0aab2b7843b0db8251d0ddf56de (diff)
downloadcgit-72fa5c63f80262019d807658cc537c9897c4b1d1.tar.gz
cgit-72fa5c63f80262019d807658cc537c9897c4b1d1.tar.bz2
cgit-72fa5c63f80262019d807658cc537c9897c4b1d1.zip
cache_safe_filename() needs more buffers
The single static buffer makes it impossible to use the result of two different calls to this function simultaneously. Fix it by using 4 buffers. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/cache.c b/cache.c
index 7cdea9b..372e38d 100644
--- a/cache.c
+++ b/cache.c
@@ -12,18 +12,23 @@ const int NOLOCK = -1;
12 12
13char *cache_safe_filename(const char *unsafe) 13char *cache_safe_filename(const char *unsafe)
14{ 14{
15 static char buf[PATH_MAX]; 15 static char buf[4][PATH_MAX];
16 char *s = buf; 16 static int bufidx;
17 char *s;
17 char c; 18 char c;
18 19
20 bufidx++;
21 bufidx &= 3;
22 s = buf[bufidx];
23
19 while(unsafe && (c = *unsafe++) != 0) { 24 while(unsafe && (c = *unsafe++) != 0) {
20 if (c == '/' || c == ' ' || c == '&' || c == '|' || 25 if (c == '/' || c == ' ' || c == '&' || c == '|' ||
21 c == '>' || c == '<' || c == '.') 26 c == '>' || c == '<' || c == '.')
22 c = '_'; 27 c = '_';
23 *s++ = c; 28 *s++ = c;
24 } 29 }
25 *s = '\0'; 30 *s = '\0';
26 return buf; 31 return buf[bufidx];
27} 32}
28 33
29int cache_exist(struct cacheitem *item) 34int cache_exist(struct cacheitem *item)