diff options
author | Petr Pudlak <petr.mvd@gmail.com> | 2013-04-12 16:21:16 +0200 |
---|---|---|
committer | Petr Pudlak <petr.mvd@gmail.com> | 2013-04-12 16:21:16 +0200 |
commit | 1b1982e9af82b3d35307b2b716651257d69c15e3 (patch) | |
tree | fac28abe0a7b0293676e60833308b6002cbc759f | |
parent | 2784d82a9e2c0712da156f30fcda80bb8060ffd9 (diff) |
Let has_cachedir_tag use `malloc` instead of a buffer on the stack.
-rw-r--r-- | src/exclude.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/exclude.c b/src/exclude.c index 97975c0..80425ec 100644 --- a/src/exclude.c +++ b/src/exclude.c @@ -104,16 +104,23 @@ void exclude_clear() { * Exclusion of directories that contain only cached information. * See http://www.brynosaurus.com/cachedir/ */ +#define CACHEDIR_TAG_FILENAME "CACHEDIR.TAG" #define CACHEDIR_TAG_SIGNATURE "Signature: 8a477f597d28d172789f06886806bc55" int has_cachedir_tag(const char *name) { - char buf[1024]; + int path_l; + char *path; + const int signature_l = sizeof CACHEDIR_TAG_SIGNATURE - 1; + char buf[signature_l]; FILE *f; int match = 0; - const int signature_l = sizeof CACHEDIR_TAG_SIGNATURE - 1; - snprintf(buf, sizeof(buf), "%s/CACHEDIR.TAG", name); - f = fopen(buf, "rb"); + path_l = strlen(name) + sizeof CACHEDIR_TAG_FILENAME + 2; + path = malloc(path_l); + snprintf(path, path_l, "%s/%s", name, CACHEDIR_TAG_FILENAME); + f = fopen(path, "rb"); + free(path); + if(f != NULL) { match = ((fread(buf, 1, signature_l, f) == signature_l) && !memcmp(buf, CACHEDIR_TAG_SIGNATURE, signature_l)); |