Properly init filename when creating node
This commit is contained in:
parent
d8379df818
commit
7e621cb64f
1 changed files with 18 additions and 1 deletions
19
haggis.c
19
haggis.c
|
@ -30,8 +30,11 @@
|
||||||
* other than his own.
|
* other than his own.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <limits.h> // PATH_MAX
|
#include <limits.h> // PATH_MAX
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h> // uint<x>_t
|
#include <stdint.h> // uint<x>_t
|
||||||
|
#include <sys/syslimits.h>
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
#include <sha.h>
|
#include <sha.h>
|
||||||
|
@ -364,7 +367,7 @@ int haggis_load_file(FILE *stream, haggis_file *f) {
|
||||||
void haggis_filename_init(char *target, haggis_filename *fname) {
|
void haggis_filename_init(char *target, haggis_filename *fname) {
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = strlen(target) - 1;
|
len = strlen(target);
|
||||||
fname->len.val = (uint16_t)len;
|
fname->len.val = (uint16_t)len;
|
||||||
fname->name = target;
|
fname->name = target;
|
||||||
}
|
}
|
||||||
|
@ -524,6 +527,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_linkmap *
|
||||||
char *target;
|
char *target;
|
||||||
char pathbuf[PATH_MAX];
|
char pathbuf[PATH_MAX];
|
||||||
int res;
|
int res;
|
||||||
|
size_t namlen;
|
||||||
haggis_node *node;
|
haggis_node *node;
|
||||||
|
|
||||||
node = calloc(1, sizeof(haggis_node));
|
node = calloc(1, sizeof(haggis_node));
|
||||||
|
@ -548,6 +552,19 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_linkmap *
|
||||||
free(node);
|
free(node);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
errno = 0;
|
||||||
|
if (file[0] == '/') {
|
||||||
|
namlen = strnlen(file, PATH_MAX - 1);
|
||||||
|
node->name.name = strndup(&file[1], namlen);
|
||||||
|
} else {
|
||||||
|
namlen = strnlen(file, PATH_MAX) + 1;
|
||||||
|
node->name.name = strndup(file, namlen);
|
||||||
|
}
|
||||||
|
if (errno == ENOMEM) {
|
||||||
|
haggis_node_deinit(node);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
node->name.len.val = (uint16_t)namlen;
|
||||||
node->uid.val = (uint32_t)st->st_uid;
|
node->uid.val = (uint32_t)st->st_uid;
|
||||||
node->gid.val = (uint32_t)st->st_gid;
|
node->gid.val = (uint32_t)st->st_gid;
|
||||||
node->mtime.val = (uint64_t)st->st_mtim.tv_sec;
|
node->mtime.val = (uint64_t)st->st_mtim.tv_sec;
|
||||||
|
|
Loading…
Add table
Reference in a new issue