summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extras/volume_id/lib/iso9660.c2
-rw-r--r--extras/volume_id/lib/util.c19
-rw-r--r--extras/volume_id/lib/util.h2
3 files changed, 17 insertions, 6 deletions
diff --git a/extras/volume_id/lib/iso9660.c b/extras/volume_id/lib/iso9660.c
index 227641e42a..1d8bdff878 100644
--- a/extras/volume_id/lib/iso9660.c
+++ b/extras/volume_id/lib/iso9660.c
@@ -91,7 +91,7 @@ int volume_id_probe_iso9660(struct volume_id *id, uint64_t off, uint64_t size)
memcmp(is->escape_sequences, "%/C", 3) == 0||
memcmp(is->escape_sequences, "%/E", 3) == 0) {
dbg("Joliet extension found");
- volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32);
+ volume_id_set_unicode16(svd_label, sizeof(svd_label), is->volume_id, BE, 32);
if (memcmp(id->label, svd_label, 16) == 0) {
dbg("SVD label is identical, use the possibly longer PVD one");
break;
diff --git a/extras/volume_id/lib/util.c b/extras/volume_id/lib/util.c
index eaaececadb..395e81bbf3 100644
--- a/extras/volume_id/lib/util.c
+++ b/extras/volume_id/lib/util.c
@@ -151,9 +151,9 @@ int volume_id_utf8_encoded_valid_unichar(const char *str)
return len;
}
-void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count)
+size_t volume_id_set_unicode16(uint8_t *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count)
{
- unsigned int i, j;
+ size_t i, j;
uint16_t c;
j = 0;
@@ -183,6 +183,7 @@ void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum end
}
}
str[j] = '\0';
+ return j;
}
static char *usage_to_string(enum volume_id_usage usage_id)
@@ -214,15 +215,22 @@ void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage_id)
void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, size_t count)
{
+ if (count > sizeof(id->label))
+ count = sizeof(id->label);
+
memcpy(id->label_raw, buf, count);
id->label_raw_len = count;
}
void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count)
{
- unsigned int i;
+ size_t i;
+
+ if (count >= sizeof(id->label))
+ count = sizeof(id->label)-1;
memcpy(id->label, buf, count);
+ id->label[count] = '\0';
/* remove trailing whitespace */
i = strnlen(id->label, count);
@@ -235,7 +243,10 @@ void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t
void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count)
{
- volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count);
+ if (count >= sizeof(id->label))
+ count = sizeof(id->label)-1;
+
+ volume_id_set_unicode16((uint8_t *)id->label, sizeof(id->label), buf, endianess, count);
}
void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, enum uuid_format format)
diff --git a/extras/volume_id/lib/util.h b/extras/volume_id/lib/util.h
index ed868001fa..14a76c8fd2 100644
--- a/extras/volume_id/lib/util.h
+++ b/extras/volume_id/lib/util.h
@@ -80,7 +80,7 @@ enum endian {
};
extern int volume_id_utf8_encoded_valid_unichar(const char *str);
-extern void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count);
+extern size_t volume_id_set_unicode16(uint8_t *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count);
extern void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage_id);
extern void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, size_t count);
extern void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count);