]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: make some string operations more robust
authorKarel Zak <kzak@redhat.com>
Fri, 15 Jun 2012 10:26:05 +0000 (12:26 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 15 Jun 2012 10:26:05 +0000 (12:26 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/cache.c
libmount/src/lock.c
libmount/src/optstr.c
libmount/src/utils.c

index 8962a903cb9f788546dcbd138946375a8134b861..fe9c821e17276a764a5c1d70c3867b9dac5542ef 100644 (file)
@@ -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"))
index 73dc6c8f7ff658815ac8b8447dc51f4c7e41e70e..80ccdeea27c2243c1bc90e704e5d492932df03a1 100644 (file)
@@ -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:
         *
index 2c9dd5eb1f88fe88c4dc89361ac866c6398a1195..bf9f8b71fd8e5f5a8ae9666f3bbf210f64cf5270 100644 (file)
@@ -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= */
index d4cc0b3ede959a9126342e703c30c7cd7386a182..63d1079d042b6add2b2f7dc41d4dcc2cdd65f70b 100644 (file)
@@ -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;