Cleaned up use of PATH_MAX (local filesystem) and LIBISOFS_NODE_PATH_MAX

(ISO filesystem).
release-1.5.4.branch
Thomas Schmitt 12 years ago
parent b200feceed
commit d1c3a017e3

@ -26,10 +26,6 @@
#include <limits.h>
#include <stdio.h>
#ifndef PATH_MAX
#define PATH_MAX Libisofs_default_path_maX
#endif
void iso_node_builder_ref(IsoNodeBuilder *builder)
@ -161,11 +157,10 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
case S_IFLNK:
{
/* source is a symbolic link */
char dest[PATH_MAX + LIBISOFS_NODE_PATH_MAX];
char dest[LIBISOFS_NODE_PATH_MAX];
IsoSymlink *link;
ret = iso_file_source_readlink(src, dest,
PATH_MAX + LIBISOFS_NODE_PATH_MAX);
ret = iso_file_source_readlink(src, dest, LIBISOFS_NODE_PATH_MAX);
if (ret < 0) {
break;
}

@ -338,7 +338,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
Ecma119Image *t;
IsoFileSrc *file;
IsoFileSrc **filelist;
char name[PATH_MAX + LIBISOFS_NODE_PATH_MAX];
char name[PATH_MAX];
char buffer[BLOCK_SIZE];
off_t file_size;
uint32_t nblocks;

@ -35,11 +35,6 @@
#include <stdio.h>
#ifndef PATH_MAX
#define PATH_MAX Libisofs_default_path_maX
#endif
/**
* Options for image reading.
* There are four kind of options:
@ -953,6 +948,7 @@ int ifs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
{
char *dest;
size_t len;
int ret;
ImageFileSourceData *data;
if (src == NULL || buf == NULL || src->data == NULL) {
@ -971,14 +967,15 @@ int ifs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
dest = (char*)data->data.content;
len = strlen(dest);
if (bufsiz <= len) {
ret = ISO_SUCCESS;
if (len >= bufsiz) {
ret = ISO_RR_PATH_TOO_LONG;
len = bufsiz - 1;
}
strncpy(buf, dest, len);
buf[len] = '\0';
return ISO_SUCCESS;
return ret;
}
static
@ -2926,11 +2923,10 @@ int image_builder_create_node(IsoNodeBuilder *builder, IsoImage *image,
case S_IFLNK:
{
/* source is a symbolic link */
char dest[PATH_MAX + LIBISOFS_NODE_PATH_MAX];
char dest[LIBISOFS_NODE_PATH_MAX];
IsoSymlink *link;
ret = iso_file_source_readlink(src, dest,
PATH_MAX + LIBISOFS_NODE_PATH_MAX);
ret = iso_file_source_readlink(src, dest, LIBISOFS_NODE_PATH_MAX);
if (ret < 0) {
free(name);
return ret;

@ -412,7 +412,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child)
static
int lfs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
{
int size;
int size, ret;
_LocalFsFileSource *data;
char *path;
@ -431,7 +431,7 @@ int lfs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
* invoke readlink, with bufsiz -1 to reserve an space for
* the NULL character
*/
size = readlink(path, buf, bufsiz - 1);
size = readlink(path, buf, bufsiz);
free(path);
if (size < 0) {
/* error */
@ -455,8 +455,13 @@ int lfs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
}
/* NULL-terminate the buf */
ret = ISO_SUCCESS;
if (size >= bufsiz) {
ret = ISO_RR_PATH_TOO_LONG;
size = bufsiz - 1;
}
buf[size] = '\0';
return ISO_SUCCESS;
return ret;
}
static

@ -44,7 +44,7 @@
/* Maximum length of a path in the libisofs node tree.
Rock Ridge specs do not impose an explicit limit on name length.
Rock Ridge specs do not impose an explicit limit on path length.
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
says

@ -869,8 +869,8 @@ void iso_stream_get_file_name(IsoStream *stream, char *name)
if (!strncmp(type, "fsrc", 4)) {
FSrcStreamData *data = stream->data;
char *path = iso_file_source_get_path(data->src);
strncpy(name, path, PATH_MAX + LIBISOFS_NODE_PATH_MAX - 1);
name[PATH_MAX + LIBISOFS_NODE_PATH_MAX - 1] = 0;
strncpy(name, path, PATH_MAX - 1);
name[PATH_MAX - 1] = 0;
free(path);
} else if (!strncmp(type, "boot", 4)) {
strcpy(name, "BOOT CATALOG");

@ -29,7 +29,8 @@ typedef struct
/**
* Get an identifier for the file of the source, for debug purposes
* @param name
* Should provide at least PATH_MAX bytes
* Must provide at least PATH_MAX bytes. If no PATH_MAX is defined
* then assume PATH_MAX = Libisofs_default_path_maX from libisofs.h
*/
void iso_stream_get_file_name(IsoStream *stream, char *name);

@ -975,19 +975,24 @@ char *iso_tree_get_node_path(IsoNode *node)
if ((IsoNode*)node->parent == node) {
return strdup("/");
} else {
char path[LIBISOFS_NODE_PATH_MAX];
char *parent_path = iso_tree_get_node_path((IsoNode*)node->parent);
char *path = NULL, *parent_path;
parent_path = iso_tree_get_node_path((IsoNode*)node->parent);
if (parent_path == NULL) {
return NULL;
}
if (strlen(parent_path) == 1) {
snprintf(path, LIBISOFS_NODE_PATH_MAX, "/%s", node->name);
path = calloc(1, strlen(node->name) + 2);
if (path == NULL)
return NULL;
sprintf(path, "/%s", node->name);
} else {
snprintf(path, LIBISOFS_NODE_PATH_MAX, "%s/%s",
parent_path, node->name);
path = calloc(1, strlen(parent_path) + strlen(node->name) + 2);
if (path == NULL)
return NULL;
sprintf(path, "%s/%s", parent_path, node->name);
}
free(parent_path);
return strdup(path);
return path;
}
}

Loading…
Cancel
Save