summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-11-27 16:08:46 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2014-11-27 16:10:44 +0100
commit0f84a72e3c0f58d71cff2121e6df1611eaf9c9ea (patch)
treedefc60dc5073ffe1c27cb2c33f6a73d2c3420619 /src/shared
parent342f3005f57fe293d3b43148f8c900f2cbc6f7f7 (diff)
resolve: fix NULL deref on strv comparison
A strv might be NULL if it is empty. The txt.strings comparison doesn't take that into account. Introduce strv_equal() to provide a proper helper for this and fix resolve to use it. Thanks to Stanisław Pitucha <viraptor@gmail.com> for reporting this!
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/strv.c11
-rw-r--r--src/shared/strv.h2
2 files changed, 13 insertions, 0 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c
index aeb93eac6b..a5f8a2aff6 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -587,6 +587,17 @@ char **strv_sort(char **l) {
return l;
}
+bool strv_equal(char **a, char **b) {
+ if (!a || !b)
+ return a == b;
+
+ for ( ; *a || *b; ++a, ++b)
+ if (!streq_ptr(*a, *b))
+ return false;
+
+ return true;
+}
+
void strv_print(char **l) {
char **s;
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 47618bd26c..774c67a8c8 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -49,6 +49,8 @@ int strv_consume_prepend(char ***l, char *value);
char **strv_remove(char **l, const char *s);
char **strv_uniq(char **l);
+bool strv_equal(char **a, char **b);
+
#define strv_contains(l, s) (!!strv_find((l), (s)))
char **strv_new(const char *x, ...) _sentinel_;