From cdd5badafd0be42f999ca1e0d69225fff2190472 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 10 Nov 2009 14:00:13 +0100 Subject: [PATCH] libblkid: don't return empty LABELs Signed-off-by: Karel Zak --- shlibs/blkid/src/blkidP.h | 1 + shlibs/blkid/src/probe.c | 21 ++++++++++++++++++++- shlibs/blkid/src/superblocks/superblocks.c | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index 6e9c21e8..90900e27 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -379,6 +379,7 @@ extern void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn extern int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn, struct blkid_prval *vals, int nvals); extern struct blkid_prval *blkid_probe_assign_value(blkid_probe pr, const char *name); +extern int blkid_probe_reset_last_value(blkid_probe pr); extern void blkid_probe_append_vals(blkid_probe pr, struct blkid_prval *vals, int nvals); extern struct blkid_chain *blkid_probe_get_chain(blkid_probe pr); diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index f8610cb6..0324351a 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -848,6 +848,25 @@ struct blkid_prval *blkid_probe_assign_value( return v; } +int blkid_probe_reset_last_value(blkid_probe pr) +{ + struct blkid_prval *v; + + if (pr == NULL || pr->nvals == 0) + return -1; + + v = &pr->vals[pr->nvals - 1]; + + DBG(DEBUG_LOWPROBE, + printf("un-assigning %s [%s]\n", v->name, v->chain->driver->name)); + + memset(v, 0, sizeof(struct blkid_prval)); + pr->nvals--; + + return 0; + +} + int blkid_probe_set_value(blkid_probe pr, const char *name, unsigned char *data, size_t len) { @@ -878,7 +897,7 @@ int blkid_probe_vsprintf_value(blkid_probe pr, const char *name, len = vsnprintf((char *) v->data, sizeof(v->data), fmt, ap); if (len <= 0) { - pr->nvals--; /* reset the latest assigned value */ + blkid_probe_reset_last_value(pr); return -1; } v->len = len + 1; diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c index 6fb2be3a..f625f271 100644 --- a/shlibs/blkid/src/superblocks/superblocks.c +++ b/shlibs/blkid/src/superblocks/superblocks.c @@ -501,6 +501,8 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len) v->data[len] = '\0'; v->len = blkid_rtrim_whitespace(v->data) + 1; + if (v->len == 1) + blkid_probe_reset_last_value(pr); return 0; } @@ -521,6 +523,8 @@ int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label, blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len); v->len = blkid_rtrim_whitespace(v->data) + 1; + if (v->len == 1) + blkid_probe_reset_last_value(pr); return 0; } -- 2.39.5