summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmount/src/cache.c6
-rw-r--r--libmount/src/lock.c4
-rw-r--r--libmount/src/optstr.c2
-rw-r--r--libmount/src/utils.c3
4 files changed, 10 insertions, 5 deletions
diff --git a/libmount/src/cache.c b/libmount/src/cache.c
index 8962a903c..fe9c821e1 100644
--- a/libmount/src/cache.c
+++ b/libmount/src/cache.c
@@ -595,7 +595,7 @@ int test_resolve_path(struct libmnt_test *ts, int argc, char *argv[])
size_t sz = strlen(line);
char *p;
- if (line[sz - 1] == '\n')
+ if (sz > 0 && line[sz - 1] == '\n')
line[sz - 1] = '\0';
p = mnt_resolve_path(line, cache);
@@ -618,7 +618,7 @@ int test_resolve_spec(struct libmnt_test *ts, int argc, char *argv[])
size_t sz = strlen(line);
char *p;
- if (line[sz - 1] == '\n')
+ if (sz > 0 && line[sz - 1] == '\n')
line[sz - 1] = '\0';
p = mnt_resolve_spec(line, cache);
@@ -641,7 +641,7 @@ int test_read_tags(struct libmnt_test *ts, int argc, char *argv[])
while(fgets(line, sizeof(line), stdin)) {
size_t sz = strlen(line);
- if (line[sz - 1] == '\n')
+ if (sz > 0 && line[sz - 1] == '\n')
line[sz - 1] = '\0';
if (!strcmp(line, "quit"))
diff --git a/libmount/src/lock.c b/libmount/src/lock.c
index 73dc6c8f7..80ccdeea2 100644
--- a/libmount/src/lock.c
+++ b/libmount/src/lock.c
@@ -138,6 +138,10 @@ int mnt_lock_use_simplelock(struct libmnt_lock *ml, int enable)
ml->simplelock = enable ? 1 : 0;
sz = strlen(ml->lockfile);
+ assert(sz);
+
+ if (sz < 1)
+ return -EINVAL;
/* Change lock name:
*
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index 2c9dd5eb1..bf9f8b71f 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -738,7 +738,7 @@ int mnt_optstr_apply_flags(char **optstr, unsigned long flags,
/* don't add options which require values (e.g. offset=%d) */
p = strchr(ent->name, '=');
if (p) {
- if (*(p - 1) == '[')
+ if (p > ent->name && *(p - 1) == '[')
p--; /* name[=] */
else
continue; /* name= */
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index d4cc0b3ed..63d1079d0 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -839,7 +839,8 @@ char *mnt_get_mountpoint(const char *path)
goto err;
dir = st.st_dev;
if (dir != base) {
- *(p - 1) = '/';
+ if (p > mnt)
+ *(p - 1) = '/';
goto done;
}
base = dir;