New error codes ISO_RR_NAME_TOO_LONG and ISO_RR_NAME_RESERVED for

occasions which previously returned ISO_WRONG_ARG_VALUE.
This commit is contained in:
Thomas Schmitt 2011-03-26 20:54:20 +01:00
parent 270cd1cad5
commit 61383dea2d
5 changed files with 58 additions and 39 deletions

View File

@ -239,6 +239,7 @@ int iso_tree_add_boot_node(IsoDir *parent, const char *name, IsoBoot **boot)
IsoBoot *node; IsoBoot *node;
IsoNode **pos; IsoNode **pos;
time_t now; time_t now;
int ret;
if (parent == NULL || name == NULL || boot == NULL) { if (parent == NULL || name == NULL || boot == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
@ -248,9 +249,9 @@ int iso_tree_add_boot_node(IsoDir *parent, const char *name, IsoBoot **boot)
} }
/* check if the name is valid */ /* check if the name is valid */
if (!iso_node_is_valid_name(name)) { ret = iso_node_is_valid_name(name);
return ISO_WRONG_ARG_VALUE; if (ret < 0)
} return ret;
/* find place where to insert */ /* find place where to insert */
pos = &(parent->children); pos = &(parent->children);

View File

@ -6828,6 +6828,13 @@ int iso_md5_match(char first_md5[16], char second_md5[16]);
/** Found copied superblock checksum tag (WARNING, HIGH, -376) */ /** Found copied superblock checksum tag (WARNING, HIGH, -376) */
#define ISO_MD5_TAG_COPIED 0xD030FE88 #define ISO_MD5_TAG_COPIED 0xD030FE88
/** Rock Ridge leaf name too long (FAILURE, HIGH, -377) */
#define ISO_RR_NAME_TOO_LONG 0xE830FE87
/** Reserved Rock Ridge leaf name (FAILURE, HIGH, -378) */
#define ISO_RR_NAME_RESERVED 0xE830FE86
/* Internal developer note: /* Internal developer note:
Place new error codes directly above this comment. Place new error codes directly above this comment.

View File

@ -455,6 +455,10 @@ const char *iso_error_to_msg(int errcode)
return "Extended information class offers no cloning method"; return "Extended information class offers no cloning method";
case ISO_MD5_TAG_COPIED: case ISO_MD5_TAG_COPIED:
return "Found copied superblock checksum tag"; return "Found copied superblock checksum tag";
case ISO_RR_NAME_TOO_LONG:
return "Rock Ridge leaf name too long";
case ISO_RR_NAME_RESERVED:
return "Reserved Rock Ridge leaf name";
default: default:
return "Unknown error"; return "Unknown error";
} }

View File

@ -325,6 +325,7 @@ enum IsoNodeType iso_node_get_type(IsoNode *node)
int iso_node_set_name(IsoNode *node, const char *name) int iso_node_set_name(IsoNode *node, const char *name)
{ {
char *new; char *new;
int ret;
if ((IsoNode*)node->parent == node) { if ((IsoNode*)node->parent == node) {
/* you can't change name of the root node */ /* you can't change name of the root node */
@ -332,9 +333,9 @@ int iso_node_set_name(IsoNode *node, const char *name)
} }
/* check if the name is valid */ /* check if the name is valid */
if (!iso_node_is_valid_name(name)) { ret = iso_node_is_valid_name(name);
return ISO_WRONG_ARG_VALUE; if (ret < 0)
} return ret;
if (node->parent != NULL) { if (node->parent != NULL) {
/* check if parent already has a node with same name */ /* check if parent already has a node with same name */
@ -1005,10 +1006,11 @@ const char *iso_symlink_get_dest(const IsoSymlink *link)
int iso_symlink_set_dest(IsoSymlink *link, const char *dest) int iso_symlink_set_dest(IsoSymlink *link, const char *dest)
{ {
char *d; char *d;
if (!iso_node_is_valid_link_dest(dest)) { int ret;
/* guard against null or empty dest */
return ISO_WRONG_ARG_VALUE; ret = iso_node_is_valid_link_dest(dest);
} if (ret < 0)
return ret;
d = strdup(dest); d = strdup(dest);
if (d == NULL) { if (d == NULL) {
return ISO_OUT_OF_MEM; return ISO_OUT_OF_MEM;
@ -1159,22 +1161,23 @@ int iso_node_is_valid_name(const char *name)
{ {
/* a name can't be NULL */ /* a name can't be NULL */
if (name == NULL) { if (name == NULL) {
return 0; return ISO_NULL_POINTER;
} }
/* guard against the empty string or big names... */ /* guard against the empty string or big names... */
if (name[0] == '\0' || strlen(name) > 255) { if (name[0] == '\0')
return 0; return ISO_RR_NAME_RESERVED;
} if (strlen(name) > 255)
return ISO_RR_NAME_TOO_LONG;
/* ...against "." and ".." names... */ /* ...against "." and ".." names... */
if (!strcmp(name, ".") || !strcmp(name, "..")) { if (!strcmp(name, ".") || !strcmp(name, "..")) {
return 0; return ISO_RR_NAME_RESERVED;
} }
/* ...and against names with '/' */ /* ...and against names with '/' */
if (strchr(name, '/') != NULL) { if (strchr(name, '/') != NULL) {
return 0; return ISO_RR_NAME_RESERVED;
} }
return 1; return 1;
} }
@ -1192,13 +1195,14 @@ int iso_node_is_valid_link_dest(const char *dest)
/* a dest can't be NULL */ /* a dest can't be NULL */
if (dest == NULL) { if (dest == NULL) {
return 0; return ISO_NULL_POINTER;
} }
/* guard against the empty string or big dest... */ /* guard against the empty string or big dest... */
if (dest[0] == '\0' || strlen(dest) > PATH_MAX) { if (dest[0] == '\0')
return 0; return ISO_RR_NAME_RESERVED;
} if (strlen(dest) > PATH_MAX)
return ISO_RR_NAME_TOO_LONG;
/* check that all components are valid */ /* check that all components are valid */
if (!strcmp(dest, "/")) { if (!strcmp(dest, "/")) {
@ -1208,7 +1212,7 @@ int iso_node_is_valid_link_dest(const char *dest)
ptr = strdup(dest); ptr = strdup(dest);
if (ptr == NULL) { if (ptr == NULL) {
return 0; return ISO_OUT_OF_MEM;
} }
ret = 1; ret = 1;
@ -1216,7 +1220,7 @@ int iso_node_is_valid_link_dest(const char *dest)
while (component) { while (component) {
if (strcmp(component, ".") && strcmp(component, "..")) { if (strcmp(component, ".") && strcmp(component, "..")) {
ret = iso_node_is_valid_name(component); ret = iso_node_is_valid_name(component);
if (ret == 0) { if (ret < 0) {
break; break;
} }
} }
@ -1375,15 +1379,16 @@ int iso_node_new_root(IsoDir **root)
int iso_node_new_dir(char *name, IsoDir **dir) int iso_node_new_dir(char *name, IsoDir **dir)
{ {
IsoDir *new; IsoDir *new;
int ret;
if (dir == NULL || name == NULL) { if (dir == NULL || name == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
/* check if the name is valid */ /* check if the name is valid */
if (!iso_node_is_valid_name(name)) { ret = iso_node_is_valid_name(name);
return ISO_WRONG_ARG_VALUE; if (ret < 0)
} return ret;
new = calloc(1, sizeof(IsoDir)); new = calloc(1, sizeof(IsoDir));
if (new == NULL) { if (new == NULL) {
@ -1400,15 +1405,16 @@ int iso_node_new_dir(char *name, IsoDir **dir)
int iso_node_new_file(char *name, IsoStream *stream, IsoFile **file) int iso_node_new_file(char *name, IsoStream *stream, IsoFile **file)
{ {
IsoFile *new; IsoFile *new;
int ret;
if (file == NULL || name == NULL || stream == NULL) { if (file == NULL || name == NULL || stream == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
/* check if the name is valid */ /* check if the name is valid */
if (!iso_node_is_valid_name(name)) { ret = iso_node_is_valid_name(name);
return ISO_WRONG_ARG_VALUE; if (ret < 0)
} return ret;
new = calloc(1, sizeof(IsoFile)); new = calloc(1, sizeof(IsoFile));
if (new == NULL) { if (new == NULL) {
@ -1428,21 +1434,21 @@ int iso_node_new_file(char *name, IsoStream *stream, IsoFile **file)
int iso_node_new_symlink(char *name, char *dest, IsoSymlink **link) int iso_node_new_symlink(char *name, char *dest, IsoSymlink **link)
{ {
IsoSymlink *new; IsoSymlink *new;
int ret;
if (link == NULL || name == NULL || dest == NULL) { if (link == NULL || name == NULL || dest == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
/* check if the name is valid */ /* check if the name is valid */
if (!iso_node_is_valid_name(name)) { ret = iso_node_is_valid_name(name);
return ISO_WRONG_ARG_VALUE; if (ret < 0)
} return ret;
/* check if destination is valid */ /* check if destination is valid */
if (!iso_node_is_valid_link_dest(dest)) { ret = iso_node_is_valid_link_dest(dest);
/* guard against null or empty dest */ if (ret < 0)
return ISO_WRONG_ARG_VALUE; return ret;
}
new = calloc(1, sizeof(IsoSymlink)); new = calloc(1, sizeof(IsoSymlink));
if (new == NULL) { if (new == NULL) {
@ -1464,6 +1470,7 @@ int iso_node_new_special(char *name, mode_t mode, dev_t dev,
IsoSpecial **special) IsoSpecial **special)
{ {
IsoSpecial *new; IsoSpecial *new;
int ret;
if (special == NULL || name == NULL) { if (special == NULL || name == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
@ -1473,9 +1480,9 @@ int iso_node_new_special(char *name, mode_t mode, dev_t dev,
} }
/* check if the name is valid */ /* check if the name is valid */
if (!iso_node_is_valid_name(name)) { ret = iso_node_is_valid_name(name);
return ISO_WRONG_ARG_VALUE; if (ret < 0)
} return ret;
new = calloc(1, sizeof(IsoSpecial)); new = calloc(1, sizeof(IsoSpecial));
if (new == NULL) { if (new == NULL) {

View File

@ -286,7 +286,7 @@ int iso_node_new_special(char *name, mode_t mode, dev_t dev,
* Check if a given name is valid for an iso node. * Check if a given name is valid for an iso node.
* *
* @return * @return
* 1 if yes, 0 if not * 1 if yes, <0 if not. The value is a specific ISO_* error code.
*/ */
int iso_node_is_valid_name(const char *name); int iso_node_is_valid_name(const char *name);