diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.c | 5 | ||||
-rw-r--r-- | libglusterfs/src/statedump.c | 17 | ||||
-rw-r--r-- | libglusterfs/src/statedump.h | 15 |
3 files changed, 24 insertions, 13 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 60725769096..09f0caa7e8a 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3061,8 +3061,9 @@ gf_canonicalize_path (char *path) strncpy ((path + path_len + 1), dir, dir_path_len); path_len += dir_path_len + 1; dir = strtok_r (NULL, "/", &tmpstr); - if (dir) - strncpy ((path + path_len), "/", 1); + if (dir) { + path[path_len] = '/'; + } } path[path_len] = '\0'; ret = 0; diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 874326f44ce..21a916ea6b8 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -858,11 +858,16 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) if (ret < 0) goto out; - snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, - ((dump_options.dump_path != NULL)?dump_options.dump_path: - ((ctx->statedump_path != NULL)?ctx->statedump_path: - DEFAULT_VAR_RUN_DIRECTORY)), brick_name, getpid(), - (uint64_t) time (NULL)); + ret = snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, + ((dump_options.dump_path != NULL) + ? dump_options.dump_path + : ((ctx->statedump_path != NULL) + ? ctx->statedump_path + : DEFAULT_VAR_RUN_DIRECTORY)), + brick_name, getpid(), (uint64_t) time (NULL)); + if ((ret < 0) || (ret >= sizeof(path))) { + goto out; + } snprintf (tmp_dump_name, PATH_MAX, "%s/dumpXXXXXX", ((dump_options.dump_path != NULL)?dump_options.dump_path: @@ -939,10 +944,10 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) timestr); ret = sys_write (gf_dump_fd, sign_string, strlen (sign_string)); -out: if (gf_dump_fd != -1) gf_proc_dump_close (); sys_rename (tmp_dump_name, path); +out: GF_FREE (dump_options.dump_path); dump_options.dump_path = NULL; gf_proc_dump_unlock (); diff --git a/libglusterfs/src/statedump.h b/libglusterfs/src/statedump.h index 0a7a97e10d4..92246e1e37e 100644 --- a/libglusterfs/src/statedump.h +++ b/libglusterfs/src/statedump.h @@ -41,13 +41,18 @@ __attribute__ ((__format__ (__printf__, 3, 4))) static inline void _gf_proc_dump_build_key (char *key, const char *prefix, const char *fmt, ...) { - char buf[GF_DUMP_MAX_BUF_LEN] = { 0, }; va_list ap; + int32_t len; - va_start(ap, fmt); - vsnprintf(buf, GF_DUMP_MAX_BUF_LEN, fmt, ap); - va_end(ap); - snprintf(key, GF_DUMP_MAX_BUF_LEN, "%s.%s", prefix, buf); + len = snprintf(key, GF_DUMP_MAX_BUF_LEN, "%s.", prefix); + if (len >= 0) { + va_start(ap, fmt); + len = vsnprintf(key + len, GF_DUMP_MAX_BUF_LEN - len, fmt, ap); + va_end(ap); + } + if (len < 0) { + *key = 0; + } } #define gf_proc_dump_build_key(key, key_prefix, fmt...) \ |