New error code ISO_RR_PATH_TOO_LONG.

This commit is contained in:
Thomas Schmitt 2011-03-28 15:00:44 +02:00
parent 61383dea2d
commit 71efc996e3
10 changed files with 70 additions and 22 deletions

View File

@ -75,6 +75,8 @@ int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
iso_file_source_ref(src); iso_file_source_ref(src);
name = iso_file_source_get_name(src); name = iso_file_source_get_name(src);
if (strlen(name) > LIBISOFS_NODE_NAME_MAX)
name[LIBISOFS_NODE_NAME_MAX] = 0;
ret = iso_node_new_file(name, stream, &node); ret = iso_node_new_file(name, stream, &node);
if (ret < 0) { if (ret < 0) {
iso_stream_unref(stream); iso_stream_unref(stream);
@ -122,6 +124,8 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
} }
name = iso_file_source_get_name(src); name = iso_file_source_get_name(src);
if (strlen(name) > LIBISOFS_NODE_NAME_MAX)
name[LIBISOFS_NODE_NAME_MAX] = 0;
fs = iso_file_source_get_filesystem(src); fs = iso_file_source_get_filesystem(src);
new = NULL; new = NULL;
@ -157,10 +161,11 @@ 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]; char dest[PATH_MAX + LIBISOFS_NODE_PATH_MAX];
IsoSymlink *link; IsoSymlink *link;
ret = iso_file_source_readlink(src, dest, PATH_MAX); ret = iso_file_source_readlink(src, dest,
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]; char name[PATH_MAX + LIBISOFS_NODE_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

@ -2926,10 +2926,11 @@ 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]; char dest[PATH_MAX + LIBISOFS_NODE_PATH_MAX];
IsoSymlink *link; IsoSymlink *link;
ret = iso_file_source_readlink(src, dest, PATH_MAX); ret = iso_file_source_readlink(src, dest,
PATH_MAX + LIBISOFS_NODE_PATH_MAX);
if (ret < 0) { if (ret < 0) {
free(name); free(name);
return ret; return ret;

View File

@ -6834,6 +6834,9 @@ int iso_md5_match(char first_md5[16], char second_md5[16]);
/** Reserved Rock Ridge leaf name (FAILURE, HIGH, -378) */ /** Reserved Rock Ridge leaf name (FAILURE, HIGH, -378) */
#define ISO_RR_NAME_RESERVED 0xE830FE86 #define ISO_RR_NAME_RESERVED 0xE830FE86
/** Rock Ridge path too long (FAILURE, HIGH, -379) */
#define ISO_RR_PATH_TOO_LONG 0xE830FE85
/* Internal developer note: /* Internal developer note:

View File

@ -459,6 +459,8 @@ const char *iso_error_to_msg(int errcode)
return "Rock Ridge leaf name too long"; return "Rock Ridge leaf name too long";
case ISO_RR_NAME_RESERVED: case ISO_RR_NAME_RESERVED:
return "Reserved Rock Ridge leaf name"; return "Reserved Rock Ridge leaf name";
case ISO_RR_PATH_TOO_LONG:
return "Rock Ridge path too long";
default: default:
return "Unknown error"; return "Unknown error";
} }

View File

@ -28,11 +28,6 @@
#include <stdio.h> #include <stdio.h>
#ifndef PATH_MAX
#define PATH_MAX Libisofs_default_path_maX
#endif
struct dir_iter_data struct dir_iter_data
{ {
/* points to the last visited child, to NULL before start */ /* points to the last visited child, to NULL before start */
@ -1167,7 +1162,7 @@ int iso_node_is_valid_name(const char *name)
/* guard against the empty string or big names... */ /* guard against the empty string or big names... */
if (name[0] == '\0') if (name[0] == '\0')
return ISO_RR_NAME_RESERVED; return ISO_RR_NAME_RESERVED;
if (strlen(name) > 255) if (strlen(name) > LIBISOFS_NODE_NAME_MAX)
return ISO_RR_NAME_TOO_LONG; return ISO_RR_NAME_TOO_LONG;
/* ...against "." and ".." names... */ /* ...against "." and ".." names... */
@ -1201,8 +1196,8 @@ int iso_node_is_valid_link_dest(const char *dest)
/* guard against the empty string or big dest... */ /* guard against the empty string or big dest... */
if (dest[0] == '\0') if (dest[0] == '\0')
return ISO_RR_NAME_RESERVED; return ISO_RR_NAME_RESERVED;
if (strlen(dest) > PATH_MAX) if (strlen(dest) > LIBISOFS_NODE_PATH_MAX)
return ISO_RR_NAME_TOO_LONG; return ISO_RR_PATH_TOO_LONG;
/* check that all components are valid */ /* check that all components are valid */
if (!strcmp(dest, "/")) { if (!strcmp(dest, "/")) {

View File

@ -30,6 +30,29 @@
#endif #endif
/* Maximum length of a leaf name in the libisofs node tree. This is currently
restricted by the implemented maximum length of a Rock Ridge name.
This might later become larger and may then be limited to smaller values.
Rock Ridge specs do not impose an explicit limit on name length.
But 255 is also specified by
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
which says
NAME_MAX >= _XOPEN_NAME_MAX = 255
*/
#define LIBISOFS_NODE_NAME_MAX 255
/* Maximum length of a path in the libisofs node tree.
Rock Ridge specs do not impose an explicit limit on name length.
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
says
PATH_MAX >= _XOPEN_PATH_MAX = 1024
*/
#define LIBISOFS_NODE_PATH_MAX 1024
/** /**
* The extended information is a way to attach additional information to each * The extended information is a way to attach additional information to each
* IsoNode. External applications may want to use this extension system to * IsoNode. External applications may want to use this extension system to

View File

@ -342,6 +342,9 @@ int rrip_add_NM(Ecma119Image *t, struct susp_info *susp, char *name, int size,
return ISO_OUT_OF_MEM; return ISO_OUT_OF_MEM;
} }
if (size > 250)
return ISO_ASSERT_FAILURE;
NM[0] = 'N'; NM[0] = 'N';
NM[1] = 'M'; NM[1] = 'M';
NM[2] = size + 5; NM[2] = size + 5;
@ -973,6 +976,18 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
*su_size += 28; *su_size += 28;
} }
/* <<< */
#ifdef NIX
{
static int min_free = 1000;
if (space - *su_size < min_free) {
min_free = space - *su_size;
fprintf(stderr, "LIBISOFS_DEBUG: minimum free SUA before NM = %d\n",
min_free);
}
}
#endif /* NIX */
/* NM entry */ /* NM entry */
if (*su_size + 5 + namelen <= space) { if (*su_size + 5 + namelen <= space) {
/* ok, it fits in System Use Area */ /* ok, it fits in System Use Area */
@ -982,6 +997,9 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
if (!(flag & 1)) if (!(flag & 1))
goto unannounced_ca; goto unannounced_ca;
namelen = namelen - (space - *su_size - 5); namelen = namelen - (space - *su_size - 5);
/* >>> Need to handle lengths > 250 */;
*ce = 5 + namelen; *ce = 5 + namelen;
*su_size = space; *su_size = space;
} }
@ -1659,6 +1677,9 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
/* /*
* ..and the part that goes to continuation area. * ..and the part that goes to continuation area.
*/ */
/* >>> Need a loop to handle lengths > 250 */;
ret = rrip_add_NM(t, info, name + namelen, strlen(name + namelen), ret = rrip_add_NM(t, info, name + namelen, strlen(name + namelen),
0, 1); 0, 1);
if (ret < 0) { if (ret < 0) {

View File

@ -16,6 +16,7 @@
#include "stream.h" #include "stream.h"
#include "fsource.h" #include "fsource.h"
#include "util.h" #include "util.h"
#include "node.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -868,7 +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); strncpy(name, path, PATH_MAX + LIBISOFS_NODE_PATH_MAX - 1);
name[PATH_MAX + LIBISOFS_NODE_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

@ -32,11 +32,6 @@
#include <fnmatch.h> #include <fnmatch.h>
#ifndef PATH_MAX
#define PATH_MAX Libisofs_default_path_maX
#endif
/** /**
* Add a new directory to the iso tree. * Add a new directory to the iso tree.
* *
@ -980,15 +975,16 @@ 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[PATH_MAX]; char path[LIBISOFS_NODE_PATH_MAX];
char *parent_path = iso_tree_get_node_path((IsoNode*)node->parent); char *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, PATH_MAX, "/%s", node->name); snprintf(path, LIBISOFS_NODE_PATH_MAX, "/%s", node->name);
} else { } else {
snprintf(path, PATH_MAX, "%s/%s", parent_path, node->name); snprintf(path, LIBISOFS_NODE_PATH_MAX, "%s/%s",
parent_path, node->name);
} }
free(parent_path); free(parent_path);
return strdup(path); return strdup(path);