summaryrefslogtreecommitdiffstats
path: root/libblkid/src/partitions
diff options
context:
space:
mode:
authorOndrej Oprala2015-02-03 16:30:15 +0100
committerKarel Zak2015-02-24 10:22:37 +0100
commit6c4a7811f85fc64cb0b0fb9f3e266592ed9c40dc (patch)
treefa3dd1b62a64c4240171fa80e9c3946e08e91b03 /libblkid/src/partitions
parentdocs: add terminal-colors requests to TODO (diff)
downloadkernel-qcow2-util-linux-6c4a7811f85fc64cb0b0fb9f3e266592ed9c40dc.tar.gz
kernel-qcow2-util-linux-6c4a7811f85fc64cb0b0fb9f3e266592ed9c40dc.tar.xz
kernel-qcow2-util-linux-6c4a7811f85fc64cb0b0fb9f3e266592ed9c40dc.zip
libblkid: make probing data structures more dynamic
* replace static probing result array with list * use allocated buffers for probing result variables [kzak@redhat.com: - rename some functions - clean up \0 terminator usage in variables - remove never used code to convert UUID to lower-case - remove possible memory leaks on errors] Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libblkid/src/partitions')
-rw-r--r--libblkid/src/partitions/partitions.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
index 4853f97e2..b28dfbd57 100644
--- a/libblkid/src/partitions/partitions.c
+++ b/libblkid/src/partitions/partitions.c
@@ -1098,11 +1098,18 @@ int blkid_partitions_set_ptuuid(blkid_probe pr, unsigned char *uuid)
return 0;
v = blkid_probe_assign_value(pr, "PTUUID");
+ if (!v)
+ return -ENOMEM;
- blkid_unparse_uuid(uuid, (char *) v->data, sizeof(v->data));
v->len = 37;
+ v->data = calloc(1, v->len);
+ if (v->data) {
+ blkid_unparse_uuid(uuid, (char *) v->data, v->len);
+ return 0;
+ }
- return 0;
+ blkid_probe_free_val(v);
+ return -ENOMEM;
}
/* set PTUUID variable for non-binary API for tables where
@@ -1110,27 +1117,14 @@ int blkid_partitions_set_ptuuid(blkid_probe pr, unsigned char *uuid)
int blkid_partitions_strcpy_ptuuid(blkid_probe pr, char *str)
{
struct blkid_chain *chn = blkid_probe_get_chain(pr);
- struct blkid_prval *v;
- size_t len;
if (chn->binary || !str || !*str)
return 0;
- len = strlen((char *) str);
- if (len > BLKID_PROBVAL_BUFSIZ)
- len = BLKID_PROBVAL_BUFSIZ;
-
- v = blkid_probe_assign_value(pr, "PTUUID");
- if (v) {
- if (len == BLKID_PROBVAL_BUFSIZ)
- len--; /* make a space for \0 */
+ if (!blkid_probe_set_value(pr, "PTUUID", (unsigned char *) str, strlen(str) + 1))
+ return -ENOMEM;
- memcpy((char *) v->data, str, len);
- v->data[len] = '\0';
- v->len = len + 1;
- return 0;
- }
- return -1;
+ return 0;
}
/**