<feed xmlns='http://www.w3.org/2005/Atom'>
<title>cgit/cache.c, branch v1.2.2</title>
<subtitle>A hyperfast web frontend for git repositories written in C.</subtitle>
<id>https://git.zx2c4.com/cgit/atom/cache.c?h=v1.2.2</id>
<link rel='self' href='https://git.zx2c4.com/cgit/atom/cache.c?h=v1.2.2'/>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/'/>
<updated>2018-06-27T16:13:03Z</updated>
<entry>
<title>cache: close race window when unlocking slots</title>
<updated>2018-06-27T16:13:03Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2018-06-20T05:29:14Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=b31e99887b17f513289fb11227b2484504e85b6c'/>
<id>urn:sha1:b31e99887b17f513289fb11227b2484504e85b6c</id>
<content type='text'>
We use POSIX advisory record locks to control access to cache slots, but
these have an unhelpful behaviour in that they are released when any
file descriptor referencing the file is closed by this process.

Mostly this is okay, since we know we won't be opening the lock file
anywhere else, but there is one place that it does matter: when we
restore stdout we dup2() over a file descriptor referring to the file,
thus closing that descriptor.

Since we restore stdout before unlocking the slot, this creates a window
during which the slot content can be overwritten.  The fix is reasonably
straightforward: simply restore stdout after unlocking the slot, but the
diff is a bit bigger because this requires us to move the temporary
stdout FD into struct cache_slot.

Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
Reviewed-by: Christian Hesse &lt;mail@eworm.de&gt;
</content>
</entry>
<entry>
<title>global: spelling fixes</title>
<updated>2017-10-15T16:44:55Z</updated>
<author>
<name>Ville Skyttä</name>
<email>ville.skytta@iki.fi</email>
</author>
<published>2017-10-14T19:05:51Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=67d0f870506e3bc3703ae3cb2cb00e19691ce967'/>
<id>urn:sha1:67d0f870506e3bc3703ae3cb2cb00e19691ce967</id>
<content type='text'>
Signed-off-by: Ville Skyttä &lt;ville.skytta@iki.fi&gt;
</content>
</entry>
<entry>
<title>cache: flush stdio before restoring FDs</title>
<updated>2017-10-03T18:19:34Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2017-04-24T18:38:34Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=3b485cc5422f800d142c7023295e82c0a1c10b19'/>
<id>urn:sha1:3b485cc5422f800d142c7023295e82c0a1c10b19</id>
<content type='text'>
As described in commit 2efb59e (ui-patch: Flush stdout after outputting
data, 2014-06-11), we need to ensure that stdout is flushed before
restoring the file descriptor when writing to the cache.  It turns out
that it's not just ui-patch that is affected by this but also raw diff
which writes to stdout internally.

Let's avoid risking more places doing this by ensuring that stdout is
flushed after writing in fill_slot().

Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
</content>
</entry>
<entry>
<title>cache: don't check for match with no key</title>
<updated>2016-01-17T16:05:39Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2016-01-16T11:03:07Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=33bc949a1e927e14479568518bd92e70998e25f8'/>
<id>urn:sha1:33bc949a1e927e14479568518bd92e70998e25f8</id>
<content type='text'>
We call open_slot() from cache_ls() without a key since we simply want
to read the path out of the header.  Should the file happen to contain
an empty key then we end up calling memcmp() with NULL and a non-zero
length.  Fix this by assigning slot-&gt;match only if a key is set, which
is always will be in the code paths where we use slot-&gt;match.

Coverity-id: 13807
Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
</content>
</entry>
<entry>
<title>cache: use size_t for string lengths</title>
<updated>2016-01-17T16:05:19Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2016-01-16T11:03:06Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=3fbfced7401cfcbb8006a9a6ce4add6b37a41a55'/>
<id>urn:sha1:3fbfced7401cfcbb8006a9a6ce4add6b37a41a55</id>
<content type='text'>
Avoid integer truncation on 64-bit systems.

Coverity-id: 13864
Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
</content>
</entry>
<entry>
<title>cache: fix resource leak: close file handle before return</title>
<updated>2015-10-10T19:41:04Z</updated>
<author>
<name>Christian Hesse</name>
<email>mail@eworm.de</email>
</author>
<published>2015-10-10T14:56:28Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=76dc7a3371e487fdc9de7b3b4c991fe370598f0e'/>
<id>urn:sha1:76dc7a3371e487fdc9de7b3b4c991fe370598f0e</id>
<content type='text'>
Coverity-id: 13910
Signed-off-by: Christian Hesse &lt;mail@eworm.de&gt;
</content>
</entry>
<entry>
<title>cache.c: fix header order</title>
<updated>2015-08-13T13:37:42Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2015-08-13T11:14:17Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=43620cf6aa62decaf319d00c28297e3b87a4da78'/>
<id>urn:sha1:43620cf6aa62decaf319d00c28297e3b87a4da78</id>
<content type='text'>
git-compat-util.h may define values that affect how system headers are
interpreted, so move sys/sendfile.h after cgit.h (which includes
git-compat-util.h).

Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
</content>
</entry>
<entry>
<title>cache: don't use an integer as a NULL pointer</title>
<updated>2015-03-09T16:40:44Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2015-03-08T16:32:26Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=80d52079f7f58d273d99745f93909e5c6524a9bd'/>
<id>urn:sha1:80d52079f7f58d273d99745f93909e5c6524a9bd</id>
<content type='text'>
Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
</content>
</entry>
<entry>
<title>cache: use F_SETLK to avoid stale lock files</title>
<updated>2015-03-03T22:55:27Z</updated>
<author>
<name>John Keeping</name>
<email>john@keeping.me.uk</email>
</author>
<published>2015-03-03T19:22:31Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=db9a70b159a107da29f88865d63ba14dd127556f'/>
<id>urn:sha1:db9a70b159a107da29f88865d63ba14dd127556f</id>
<content type='text'>
If CGit is killed while it holds a lock on a cache slot (for example
because it is taking too long to generate a page), the lock file will be
left in place.  This prevents any future attempt to use the same slot
since it will fail to exclusively create the lock file.

Since CGit is the only program that should be manipulating lock files,
we can use advisory locking to detect whether another process is
actually using the lock file or if it is now stale.

I have confirmed that this works on Linux by setting a short TTL in a
custom cgitrc and running the following with CGit patched to print a
message to stderr if the fcntl(2) fails:

	$ export CGIT_CONFIG=$PWD/cgitrc
	$ export QUERY_STRING=url=cgit/tree/ui-shared.c
	$ ./cgit |
		grep -v -e '^&lt;div class=.footer.&gt;' \
			-e '^Last-Modified: ' \
			-e ^'Expires: ' &gt;expect
	$ seq 50000 | dd bs=8192 |
		parallel -j200 "diff -u expect &lt;(./cgit |
			grep -v -e '^&lt;div class=.footer.&gt;' \
				-e '^Last-Modified: ' \
				-e ^'Expires: ') || echo BAD"

This printed the fail message several times without ever printing "BAD".

Signed-off-by: John Keeping &lt;john@keeping.me.uk&gt;
</content>
</entry>
<entry>
<title>Skip cache slot when time-to-live is zero</title>
<updated>2014-02-21T00:19:45Z</updated>
<author>
<name>Lukas Fleischer</name>
<email>cgit@cryptocrack.de</email>
</author>
<published>2014-02-20T19:59:22Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/cgit/commit/?id=6ceba453a27ead382d0116d95bdeb6b6be1149e2'/>
<id>urn:sha1:6ceba453a27ead382d0116d95bdeb6b6be1149e2</id>
<content type='text'>
If time-to-live is set to zero, we don't need to regenerate the cache
slots on every request. Instead, just skip the caching process and
immediately provide the dynamically generated version of the page.
Setting time-to-live to zero is useful when you want to disable caching
for certain pages.

Signed-off-by: Lukas Fleischer &lt;cgit@cryptocrack.de&gt;
</content>
</entry>
</feed>
