summaryrefslogtreecommitdiff
path: root/extras/volume_id/lib/util.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-05-25 03:35:18 +0200
committerKay Sievers <kay.sievers@vrfy.org>2007-05-25 03:35:18 +0200
commita3b836c6c22614d2aa746d89ddfaa6888e47691f (patch)
treeaddf1bdb6d7918839671bae3542c776613281374 /extras/volume_id/lib/util.c
parent52e1af940af52a4f1c2f512eef82249aa081535e (diff)
volume_id: terminate overlong label strings
Diffstat (limited to 'extras/volume_id/lib/util.c')
-rw-r--r--extras/volume_id/lib/util.c19
1 files changed, 15 insertions, 4 deletions
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)