From: Karel Zak Date: Fri, 15 Jun 2012 10:26:05 +0000 (+0200) Subject: libmount: make some string operations more robust X-Git-Tag: v2.22-rc1~278 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d670a2ab4b5b6d5a19aa4d392353f64b7218a5b;p=thirdparty%2Futil-linux.git libmount: make some string operations more robust Signed-off-by: Karel Zak --- diff --git a/libmount/src/cache.c b/libmount/src/cache.c index 8962a903cb..fe9c821e17 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 73dc6c8f7f..80ccdeea27 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 2c9dd5eb1f..bf9f8b71fd 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 d4cc0b3ede..63d1079d04 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;