diff --git a/libisofs/fs_image.c b/libisofs/fs_image.c index 30550c9..d4f0c95 100644 --- a/libisofs/fs_image.c +++ b/libisofs/fs_image.c @@ -2133,9 +2133,12 @@ int read_pvm(_ImageFsData *data, uint32_t block) data->data_preparer_id = strcopy((char*)pvm->data_prep_id, 128); data->system_id = strcopy((char*)pvm->system_id, 32); data->application_id = strcopy((char*)pvm->application_id, 128); - data->copyright_file_id = strcopy((char*)pvm->copyright_file_id, 37); - data->abstract_file_id = strcopy((char*)pvm->abstract_file_id, 37); - data->biblio_file_id = strcopy((char*)pvm->bibliographic_file_id, 37); + data->copyright_file_id = + iso_util_strcopy_untail((char*) pvm->copyright_file_id, 37); + data->abstract_file_id = + iso_util_strcopy_untail((char*) pvm->abstract_file_id, 37); + data->biblio_file_id = + iso_util_strcopy_untail((char*) pvm->bibliographic_file_id, 37); data->nblocks = iso_read_bb(pvm->vol_space_size, 4, NULL); diff --git a/libisofs/util.c b/libisofs/util.c index dfd7cac..227c20a 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -1392,13 +1392,36 @@ char *strcopy(const char *buf, size_t len) strncpy(str, buf, len); str[len] = '\0'; - /* remove trailing spaces */ + /* remove trailing spaces + (This leaves the space at str[0] existing. Bug or feature ?) + */ for (len = len-1; str[len] == ' ' && len > 0; --len) str[len] = '\0'; return str; } +char *iso_util_strcopy_untail(const char *buf, size_t len) +{ + char *str; + + str = malloc((len + 1) * sizeof(char)); + if (str == NULL) { + return NULL; + } + strncpy(str, buf, len); + str[len] = 0; + + /* remove trailing spaces */ + for (len = len-1; len >= 0; --len) { + if (str[len] != ' ') + break; + str[len] = 0; + } + + return str; +} + /** * Copy up to \p max characters from \p src to \p dest. If \p src has less than * \p max characters, we pad dest with " " characters. diff --git a/libisofs/util.h b/libisofs/util.h index be56625..9f51390 100644 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -249,9 +249,19 @@ int iso_eaccess(const char *path); /** * Copy up to \p len chars from \p buf and return this newly allocated * string. The new string is null-terminated. + * Note: + * Trailing blanks will be removed. But the first one of an all blank string + * persists. It is unclear whether this is a bug or a feature. */ char *strcopy(const char *buf, size_t len); +/** + * Copy up to \p len chars from \p buf and return this newly allocated + * string. The new string is null-terminated. + * Any trailing blanks will be removed. + */ +char *iso_util_strcopy_untail(const char *buf, size_t len); + /** * Copy up to \p max characters from \p src to \p dest. If \p src has less than * \p max characters, we pad dest with " " characters.