Cleaned up use of PATH_MAX (local filesystem) and LIBISOFS_NODE_PATH_MAX

(ISO filesystem).
This commit is contained in:
Thomas Schmitt 2011-04-03 11:02:15 +02:00
parent b200feceed
commit d1c3a017e3
8 changed files with 35 additions and 33 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -44,7 +44,7 @@
/* Maximum length of a path in the libisofs node tree. /* 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 http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
says says

View File

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

View File

@ -29,7 +29,8 @@ typedef struct
/** /**
* Get an identifier for the file of the source, for debug purposes * Get an identifier for the file of the source, for debug purposes
* @param name * @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); void iso_stream_get_file_name(IsoStream *stream, char *name);

View File

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