summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2011-10-05 18:01:56 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2011-10-05 18:09:01 +0100
commit0575841c499e85e46939bb0f472c8a68fa27b77c (patch)
tree0d624ba6fe6692e1f1f67b1485ce4e0d912acb6f
parent5b1b9e9c6badfb57352522cb6d9d12ca109b5c1e (diff)
downloadtbdiff-0575841c499e85e46939bb0f472c8a68fa27b77c.tar.gz
Fixed paths being corrupted and making garbage paths appear
struct dirent pointer returned from readdir was being used after the DIR had been closed. malloc was reusing that memory when trying to construct a tbd_stat_t, but tried to fill it with data from the struct dirent which was owned by the DIR.
-rw-r--r--libtbd_stat.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libtbd_stat.c b/libtbd_stat.c
index b7f03ea..dacbe12 100644
--- a/libtbd_stat.c
+++ b/libtbd_stat.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <stddef.h>
#include <string.h>
#include <inttypes.h>
@@ -141,14 +142,16 @@ tbd_stat_entry(tbd_stat_t *file, uint32_t entry)
(strcmp(ds->d_name, "..") == 0))
i--;
}
+ char *name = strndup(ds->d_name, ds->d_reclen-offsetof(struct dirent, d_name));
closedir (dp);
- char *spath = tbd_stat_subpath(file, ds->d_name);
+ char *spath = tbd_stat_subpath(file, name);
if(spath == NULL)
return NULL;
- tbd_stat_t *ret = tbd_stat_from_path(ds->d_name, (const char*)spath);
+ tbd_stat_t *ret = tbd_stat_from_path(name, (const char*)spath);
+ free(name);
free(spath);
if (ret == NULL)