summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-rpc-ops.c10
-rw-r--r--configure.ac3
-rw-r--r--libglusterfs/src/common-utils.c5
-rw-r--r--libglusterfs/src/statedump.c17
-rw-r--r--libglusterfs/src/statedump.h15
-rw-r--r--rpc/rpc-lib/src/xdr-rpc.h2
-rw-r--r--rpc/rpc-transport/socket/src/socket.c25
-rw-r--r--xlators/cluster/dht/src/tier.c37
-rw-r--r--xlators/debug/trace/src/trace.c116
-rw-r--r--xlators/features/bit-rot/src/bitd/bit-rot-scrub.c8
-rw-r--r--xlators/features/changelog/src/changelog-helpers.c39
-rw-r--r--xlators/features/index/src/index.c19
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-brick-ops.c23
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-geo-rep.c255
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c17
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handshake.c20
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.c18
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.h10
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-mgmt.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c65
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-quota.c50
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapd-svc-helper.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapd-svc.c17
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c34
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c182
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-statedump.c12
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c230
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c10
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-tier.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-tierd-svc.c17
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c273
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c62
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volume-ops.c64
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c74
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h220
-rw-r--r--xlators/storage/posix/src/posix-helpers.c30
39 files changed, 1392 insertions, 630 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 8da3fc8aa6c..602267b06a2 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -8240,8 +8240,8 @@ cli_print_volume_status_tasks (dict_t *dict)
char *op = NULL;
char *task_id_str = NULL;
char *volname = NULL;
- char key[1024] = {0,};
- char task[1024] = {0,};
+ char key[64] = {0,};
+ char task[32] = {0,};
char *brick = NULL;
ret = dict_get_str (dict, "volname", &volname);
@@ -10627,7 +10627,7 @@ gf_cli_generate_snapshot_event (gf_cli_rsp *rsp, dict_t *dict,
char *auto_delete = NULL;
char *snap_activate = NULL;
char msg[PATH_MAX] = {0, };
- char option[PATH_MAX] = {0, };
+ char option[512] = {0, };
GF_VALIDATE_OR_GOTO ("cli", dict, out);
GF_VALIDATE_OR_GOTO ("cli", rsp, out);
@@ -11846,9 +11846,9 @@ cli_to_glusterd (gf_cli_req *req, call_frame_t *frame,
}
for (i = 0; words[i]; i++) {
- strncat (cmd, words[i], strlen (words[i]));
+ strncat (cmd, words[i], len - 1);
if (words[i+1] != NULL)
- strncat (cmd, " ", strlen (" "));
+ strncat (cmd, " ", len - 1);
}
cmd [len - 1] = '\0';
diff --git a/configure.ac b/configure.ac
index c20309b232e..627a7a939a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -702,9 +702,6 @@ fi
AM_CONDITIONAL([ENABLE_BD_XLATOR], [test x$BUILD_BD_XLATOR = xyes])
-dnl check for old openssl
-AC_CHECK_LIB([crypto], CRYPTO_THREADID_set_callback, [AC_DEFINE([HAVE_CRYPTO_THREADID], [1], [use new OpenSSL functions])])
-
AC_CHECK_LIB([ssl], TLS_method, [HAVE_OPENSSL_1_1="yes"], [HAVE_OPENSSL_1_1="no"])
if test "x$HAVE_OPENSSL_1_1" = "xyes"; then
AC_DEFINE([HAVE_TLS_METHOD], [1], [Using OpenSSL-1.1 TLS_method])
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...) \
diff --git a/rpc/rpc-lib/src/xdr-rpc.h b/rpc/rpc-lib/src/xdr-rpc.h
index 5560e89328f..9f0e78a0fc1 100644
--- a/rpc/rpc-lib/src/xdr-rpc.h
+++ b/rpc/rpc-lib/src/xdr-rpc.h
@@ -75,7 +75,7 @@ xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au,
#define rpc_call_verf_len(call) (rpc_opaque_auth_len ((&(call)->ru.RM_cmb.cb_verf)))
-#if defined(GF_DARWIN_HOST_OS) || defined (IPV6_DEFAULT)
+#if defined(GF_DARWIN_HOST_OS) || !defined (HAVE_RPC_RPC_H)
#define GF_PRI_RPC_XID PRIu32
#define GF_PRI_RPC_VERSION PRIu32
#define GF_PRI_RPC_PROG_ID PRIu32
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 34bdbdea9d0..3d0e22b88f9 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -4128,6 +4128,7 @@ out:
}
+#if OPENSSL_VERSION_NUMBER < 0x1010000f
static pthread_mutex_t *lock_array = NULL;
static void
@@ -4140,7 +4141,7 @@ locking_func (int mode, int type, const char *file, int line)
}
}
-#if HAVE_CRYPTO_THREADID
+#if OPENSSL_VERSION_NUMBER >= 0x1000000f
static void
threadid_func (CRYPTO_THREADID *id)
{
@@ -4163,15 +4164,15 @@ legacy_threadid_func (void)
/* See comments above, it applies here too. */
return (unsigned long)pthread_self();
}
-#endif
+#endif /* OPENSSL_VERSION_NUMBER >= 0x1000000f */
+#endif /* OPENSSL_VERSION_NUMBER < 0x1010000f */
static void
init_openssl_mt (void)
{
- int num_locks = CRYPTO_num_locks();
- int i;
+ static gf_boolean_t initialized = _gf_false;
- if (lock_array) {
+ if (initialized) {
/* this only needs to be initialized once GLOBALLY no
matter how many translators/sockets we end up with. */
return;
@@ -4180,25 +4181,32 @@ init_openssl_mt (void)
SSL_library_init();
SSL_load_error_strings();
+ initialized = _gf_true;
+
+#if OPENSSL_VERSION_NUMBER < 0x1010000f
+ int num_locks = CRYPTO_num_locks();
+ int i;
+
lock_array = GF_CALLOC (num_locks, sizeof(pthread_mutex_t),
gf_sock_mt_lock_array);
if (lock_array) {
for (i = 0; i < num_locks; ++i) {
pthread_mutex_init (&lock_array[i], NULL);
}
-#if HAVE_CRYPTO_THREADID
+#if OPENSSL_VERSION_NUMBER >= 0x1000000f
CRYPTO_THREADID_set_callback (threadid_func);
#else /* older openssl */
CRYPTO_set_id_callback (legacy_threadid_func);
#endif
CRYPTO_set_locking_callback (locking_func);
}
-
+#endif
}
static void __attribute__((destructor))
fini_openssl_mt (void)
{
+#if OPENSSL_VERSION_NUMBER < 0x1010000f
int i;
if (!lock_array) {
@@ -4206,7 +4214,7 @@ fini_openssl_mt (void)
}
CRYPTO_set_locking_callback(NULL);
-#if HAVE_CRYPTO_THREADID
+#if OPENSSL_VERSION_NUMBER >= 0x1000000f
CRYPTO_THREADID_set_callback (NULL);
#else /* older openssl */
CRYPTO_set_id_callback (NULL);
@@ -4218,6 +4226,7 @@ fini_openssl_mt (void)
GF_FREE (lock_array);
lock_array = NULL;
+#endif
ERR_free_strings();
}
diff --git a/xlators/cluster/dht/src/tier.c b/xlators/cluster/dht/src/tier.c
index 5fa50a26d80..e4294f4fda9 100644
--- a/xlators/cluster/dht/src/tier.c
+++ b/xlators/cluster/dht/src/tier.c
@@ -1690,7 +1690,7 @@ tier_migrate_files_using_qfile (migration_args_t *comp,
int ret = -1;
tier_brick_list_t *local_brick = NULL;
tier_brick_list_t *temp = NULL;
- char query_file_path_err[PATH_MAX+128] = {0,};
+ char query_file_path_err[PATH_MAX] = {0,};
struct tm tm = {0,};
gfdb_time_t current_time = {0,};
char time_str[128] = {0,};
@@ -1698,6 +1698,7 @@ tier_migrate_files_using_qfile (migration_args_t *comp,
int count = 0;
int temp_fd = 0;
gf_tier_conf_t *tier_conf = NULL;
+ int32_t len = 0;
tier_conf = &(query_cbk_args->defrag->tier_conf);
@@ -1762,14 +1763,17 @@ out:
list_for_each_entry_safe (local_brick, temp, comp->brick_list,
list) {
/* rename error qfile*/
- snprintf (query_file_path_err,
- sizeof (query_file_path_err),
- "%s-%s.err", local_brick->qfile_path,
- time_str);
- if (sys_rename (local_brick->qfile_path,
- query_file_path_err) == -1)
- gf_msg_debug ("tier", 0, "rename "
- "failed");
+ len = snprintf (query_file_path_err,
+ sizeof (query_file_path_err),
+ "%s-%s.err", local_brick->qfile_path,
+ time_str);
+ if ((len >= 0) &&
+ (len < sizeof(query_file_path_err))) {
+ if (sys_rename (local_brick->qfile_path,
+ query_file_path_err) == -1)
+ gf_msg_debug ("tier", 0, "rename "
+ "failed");
+ }
}
}
@@ -2118,6 +2122,7 @@ tier_get_bricklist (xlator_t *xl, struct list_head *local_bricklist_head)
char db_name[PATH_MAX] = "";
int ret = 0;
tier_brick_list_t *local_brick = NULL;
+ int32_t len = 0;
GF_VALIDATE_OR_GOTO ("tier", xl, out);
GF_VALIDATE_OR_GOTO ("tier", local_bricklist_head, out);
@@ -2155,12 +2160,20 @@ tier_get_bricklist (xlator_t *xl, struct list_head *local_bricklist_head)
DHT_MSG_LOG_TIER_STATUS,
"Failed to allocate memory for"
" bricklist.");
+ ret = -1;
goto out;
}
- snprintf(local_brick->brick_db_path,
- PATH_MAX, "%s/%s/%s", rv,
- GF_HIDDEN_PATH, db_name);
+ len = snprintf(local_brick->brick_db_path,
+ PATH_MAX, "%s/%s/%s", rv,
+ GF_HIDDEN_PATH, db_name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ gf_msg ("tier", GF_LOG_ERROR, EINVAL,
+ DHT_MSG_LOG_TIER_STATUS,
+ "DB path too long");
+ ret = -1;
+ goto out;
+ }
local_brick->xlator = xl;
diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c
index be2f84d936f..ec14a6dbb1b 100644
--- a/xlators/debug/trace/src/trace.c
+++ b/xlators/debug/trace/src/trace.c
@@ -22,9 +22,9 @@
static void
trace_stat_to_str(struct iatt *buf, char *str, size_t len)
{
- char atime_buf[256] = {0,};
- char mtime_buf[256] = {0,};
- char ctime_buf[256] = {0,};
+ char atime_buf[200] = {0,};
+ char mtime_buf[200] = {0,};
+ char ctime_buf[200] = {0,};
if (!buf)
return;
@@ -80,9 +80,9 @@ trace_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
struct iatt *preparent, struct iatt *postparent,
dict_t *xdata)
{
- char statstr[4096] = {0, };
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -155,7 +155,7 @@ trace_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *buf,
dict_t *xdata)
{
- char statstr[4096] = {0, };
+ char statstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -166,18 +166,18 @@ trace_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
char string[4096] = {0,};
if (op_ret == 0) {
TRACE_STAT_TO_STR (buf, statstr);
- snprintf (string, sizeof (string),
- "%"PRId64": gfid=%s op_ret=%d buf=%s",
- frame->root->unique,
- uuid_utoa (frame->local), op_ret,
- statstr);
+ (void)snprintf (string, sizeof (string),
+ "%"PRId64": gfid=%s op_ret=%d buf=%s",
+ frame->root->unique,
+ uuid_utoa (frame->local), op_ret,
+ statstr);
} else {
- snprintf (string, sizeof (string),
- "%"PRId64": gfid=%s op_ret=%d, "
- "op_errno=%d)",
- frame->root->unique,
- uuid_utoa (frame->local), op_ret,
- op_errno);
+ (void)snprintf (string, sizeof (string),
+ "%"PRId64": gfid=%s op_ret=%d, "
+ "op_errno=%d)",
+ frame->root->unique,
+ uuid_utoa (frame->local), op_ret,
+ op_errno);
}
LOG_ELEMENT (conf, string);
}
@@ -192,7 +192,7 @@ trace_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t count, struct iatt *buf, struct iobref *iobref,
dict_t *xdata)
{
- char statstr[4096] = {0, };
+ char statstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -229,8 +229,8 @@ trace_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata)
{
- char preopstr[4096] = {0, };
- char postopstr[4096] = {0, };
+ char preopstr[1024] = {0, };
+ char postopstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -295,7 +295,7 @@ trace_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
dict_t *xdata)
{
int count = 0;
- char statstr[4096] = {0,};
+ char statstr[1024] = {0,};
char string[4096] = {0,};
trace_conf_t *conf = NULL;
gf_dirent_t *entry = NULL;
@@ -334,8 +334,8 @@ trace_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata)
{
- char preopstr[4096] = {0, };
- char postopstr[4096] = {0, };
+ char preopstr[1024] = {0, };
+ char postopstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -375,8 +375,8 @@ trace_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *statpre, struct iatt *statpost, dict_t *xdata)
{
- char preopstr[4096] = {0, };
- char postopstr[4096] = {0, };
+ char preopstr[1024] = {0, };
+ char postopstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -414,8 +414,8 @@ trace_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *statpre, struct iatt *statpost, dict_t *xdata)
{
- char preopstr[4096] = {0, };
- char postopstr[4096] = {0, };
+ char preopstr[1024] = {0, };
+ char postopstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -453,8 +453,8 @@ trace_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
struct iatt *preparent, struct iatt *postparent,
dict_t *xdata)
{
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -498,11 +498,11 @@ trace_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
struct iatt *prenewparent, struct iatt *postnewparent,
dict_t *xdata)
{
- char statstr[4096] = {0, };
- char preoldparentstr[4096] = {0, };
- char postoldparentstr[4096] = {0, };
- char prenewparentstr[4096] = {0, };
- char postnewparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char preoldparentstr[1024] = {0, };
+ char postoldparentstr[1024] = {0, };
+ char prenewparentstr[1024] = {0, };
+ char postnewparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -510,7 +510,7 @@ trace_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (!conf->log_file && !conf->log_history)
goto out;
if (trace_fop_names[GF_FOP_RENAME].enabled) {
- char string[4096] = {0,};
+ char string[6044] = {0,};
if (op_ret == 0) {
TRACE_STAT_TO_STR (buf, statstr);
TRACE_STAT_TO_STR (preoldparent, preoldparentstr);
@@ -549,7 +549,7 @@ trace_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
const char *buf, struct iatt *stbuf, dict_t *xdata)
{
- char statstr[4096] = {0, };
+ char statstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -588,8 +588,8 @@ trace_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
inode_t *inode, struct iatt *buf,
dict_t *xdata, struct iatt *postparent)
{
- char statstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -638,9 +638,9 @@ trace_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
struct iatt *preparent, struct iatt *postparent,
dict_t *xdata)
{
- char statstr[4096] = {0, };
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -682,9 +682,9 @@ trace_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
inode_t *inode, struct iatt *buf,
struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- char statstr[4096] = {0, };
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -726,9 +726,9 @@ trace_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
inode_t *inode, struct iatt *buf,
struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- char statstr[4096] = {0, };
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -770,9 +770,9 @@ trace_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
inode_t *inode, struct iatt *buf,
struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- char statstr[4096] = {0, };
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char statstr[1024] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -866,8 +866,8 @@ trace_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- char preparentstr[4096] = {0, };
- char postparentstr[4096] = {0, };
+ char preparentstr[1024] = {0, };
+ char postparentstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -906,8 +906,8 @@ trace_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata)
{
- char preopstr[4096] = {0, };
- char postopstr[4096] = {0, };
+ char preopstr[1024] = {0, };
+ char postopstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -1166,8 +1166,8 @@ trace_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata)
{
- char prebufstr[4096] = {0, };
- char postbufstr[4096] = {0, };
+ char prebufstr[1024] = {0, };
+ char postbufstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
@@ -1204,7 +1204,7 @@ int
trace_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata)
{
- char statstr[4096] = {0, };
+ char statstr[1024] = {0, };
trace_conf_t *conf = NULL;
conf = this->private;
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
index ee996525f76..e393ae0f64e 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
@@ -1750,6 +1750,7 @@ br_collect_bad_objects_of_child (xlator_t *this, br_child_t *child,
char *entry = NULL;
char tmp[PATH_MAX] = {0, };
char *path = NULL;
+ int32_t len = 0;
ret = dict_get_int32 (child_dict, "count", &count);
if (ret)
@@ -1764,8 +1765,11 @@ br_collect_bad_objects_of_child (xlator_t *this, br_child_t *child,
continue;
ret = dict_get_str (child_dict, entry, &path);
- snprintf (tmp, PATH_MAX, "%s ==> BRICK: %s\n path: %s",
- entry, child->brick_path, path);
+ len = snprintf (tmp, PATH_MAX, "%s ==> BRICK: %s\n path: %s",
+ entry, child->brick_path, path);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ continue;
+ }
snprintf (main_key, PATH_MAX, "quarantine-%d",
tmp_count);
diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c
index 306287ecd11..8bc994fa417 100644
--- a/xlators/features/changelog/src/changelog-helpers.c
+++ b/xlators/features/changelog/src/changelog-helpers.c
@@ -629,6 +629,7 @@ htime_open (xlator_t *this,
ssize_t size = 0;
struct stat stat_buf = {0,};
unsigned long record_len = 0;
+ int32_t len = 0;
CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
@@ -672,8 +673,12 @@ htime_open (xlator_t *this,
gf_smsg (this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO,
"HTIME_CURRENT",
"path=%s", ht_file_bname, NULL);
- (void) snprintf (ht_file_path, PATH_MAX, "%s/%s",
- ht_dir_path, ht_file_bname);
+ len = snprintf (ht_file_path, PATH_MAX, "%s/%s", ht_dir_path,
+ ht_file_bname);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
/* Open in append mode as existing htime file is used */
flags |= (O_RDWR | O_SYNC | O_APPEND);
@@ -763,6 +768,7 @@ htime_create (xlator_t *this,
char ht_file_path[PATH_MAX] = {0,};
char ht_file_bname[NAME_MAX + 1] = {0,};
int flags = 0;
+ int32_t len = 0;
gf_smsg (this->name, GF_LOG_INFO, 0,
CHANGELOG_MSG_HTIME_INFO, "Changelog enable: Creating new "
@@ -773,8 +779,12 @@ htime_create (xlator_t *this,
CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
/* get the htime file name in ht_file_path */
- (void) snprintf (ht_file_path,PATH_MAX,"%s/%s.%lu",ht_dir_path,
+ len = snprintf (ht_file_path, PATH_MAX, "%s/%s.%lu", ht_dir_path,
HTIME_FILE_NAME, ts);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
flags |= (O_CREAT | O_RDWR | O_SYNC);
ht_file_fd = open (ht_file_path, flags,
@@ -865,12 +875,16 @@ changelog_snap_open (xlator_t *this,
char buffer[1024] = {0,};
char c_snap_path[PATH_MAX] = {0,};
char csnap_dir_path[PATH_MAX] = {0,};
+ int32_t len = 0;
CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir_path);
- (void) snprintf (c_snap_path, PATH_MAX,
- "%s/"CSNAP_FILE_NAME,
+ len = snprintf (c_snap_path, PATH_MAX, "%s/"CSNAP_FILE_NAME,
csnap_dir_path);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
flags |= (O_CREAT | O_RDWR | O_TRUNC);
@@ -2002,8 +2016,12 @@ resolve_pargfid_to_path (xlator_t *this, const uuid_t pgfid,
priv->changelog_brick);
while (!(__is_root_gfid (pargfid))) {
- snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
- pargfid[0], pargfid[1], uuid_utoa (pargfid));
+ len = snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
+ pargfid[0], pargfid[1], uuid_utoa (pargfid));
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
len = sys_readlink (dir_handle, linkname, PATH_MAX);
if (len < 0) {
@@ -2023,7 +2041,12 @@ resolve_pargfid_to_path (xlator_t *this, const uuid_t pgfid,
&saveptr);
dir_name = strtok_r (NULL, "/", &saveptr);
- snprintf (result, PATH_MAX, "%s/%s", dir_name, pre_dir_name);
+ len = snprintf (result, PATH_MAX, "%s/%s", dir_name,
+ pre_dir_name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
strncpy (pre_dir_name, result, sizeof(pre_dir_name));
gf_uuid_parse (pgfidstr, tmp_gfid);
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
index f39d901d624..86c21e9aa83 100644
--- a/xlators/features/index/src/index.c
+++ b/xlators/features/index/src/index.c
@@ -810,6 +810,7 @@ index_entry_create (xlator_t *this, inode_t *inode, char *filename)
char entry_path[PATH_MAX] = {0};
index_priv_t *priv = NULL;
index_inode_ctx_t *ctx = NULL;
+ int32_t len = 0;
priv = this->private;
@@ -841,10 +842,15 @@ index_entry_create (xlator_t *this, inode_t *inode, char *filename)
ctx->state[ENTRY_CHANGES] = IN;
}
+ len = snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
+ filename);
+ if ((len < 0) || (len >= sizeof(entry_path))) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
op_errno = 0;
- snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
- filename);
ret = index_link_to_base (this, entry_path, ENTRY_CHANGES_SUBDIR);
out:
if (op_errno)
@@ -860,6 +866,7 @@ index_entry_delete (xlator_t *this, uuid_t pgfid, char *filename)
char pgfid_path[PATH_MAX] = {0};
char entry_path[PATH_MAX] = {0};
index_priv_t *priv = NULL;
+ int32_t len = 0;
priv = this->private;
@@ -870,8 +877,12 @@ index_entry_delete (xlator_t *this, uuid_t pgfid, char *filename)
make_gfid_path (priv->index_basepath, ENTRY_CHANGES_SUBDIR, pgfid,
pgfid_path, sizeof (pgfid_path));
- snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
- filename);
+ len = snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
+ filename);
+ if ((len < 0) || (len >= sizeof(entry_path))) {
+ op_errno = EINVAL;
+ goto out;
+ }
ret = sys_unlink (entry_path);
if (ret && (errno != ENOENT)) {
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
index c82bc3158e1..3362f7323c9 100644
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
@@ -783,6 +783,7 @@ glusterd_set_detach_bricks(dict_t *dict, glusterd_volinfo_t *volinfo)
int hot_brick_num = 0;
glusterd_brickinfo_t *brickinfo;
int ret = 0;
+ int32_t len = 0;
/* cold tier bricks at tail of list so use reverse iteration */
cds_list_for_each_entry_reverse (brickinfo, &volinfo->bricks,
@@ -791,9 +792,12 @@ glusterd_set_detach_bricks(dict_t *dict, glusterd_volinfo_t *volinfo)
if (brick_num > volinfo->tier_info.cold_brick_count) {
hot_brick_num++;
sprintf (key, "brick%d", hot_brick_num);
- snprintf (value, 256, "%s:%s",
- brickinfo->hostname,
- brickinfo->path);
+ len = snprintf (value, sizeof(value), "%s:%s",
+ brickinfo->hostname,
+ brickinfo->path);
+ if ((len < 0) || (len >= sizeof(value))) {
+ return -1;
+ }
ret = dict_set_str (dict, key, strdup(value));
if (ret)
@@ -1677,6 +1681,7 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
char *str_ret = NULL;
gf_boolean_t is_force = _gf_false;
glusterd_conf_t *conf = NULL;
+ uint32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -1778,10 +1783,14 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
continue;
if (brickinfo->status == GF_BRICK_STOPPED) {
ret = -1;
- snprintf (msg, sizeof (msg), "Brick %s is down,"
- " changing replica count needs all "
- "the bricks to be up to avoid data "
- "loss", brickinfo->path);
+ len = snprintf (msg, sizeof (msg), "Brick %s "
+ "is down, changing replica "
+ "count needs all the bricks "
+ "to be up to avoid data loss",
+ brickinfo->path);
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
gf_msg (THIS->name, GF_LOG_ERROR, 0,
GD_MSG_BRICK_ADD_FAIL, "%s", msg);
*op_errstr = gf_strdup (msg);
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
index fa40674510f..5a5d4ec2540 100644
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
@@ -941,6 +941,7 @@ gsyncd_getpidfile (char *master, char *slave, char *pidfile,
int ret = -1;
struct stat stbuf = {0,};
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -953,8 +954,11 @@ gsyncd_getpidfile (char *master, char *slave, char *pidfile,
GF_VALIDATE_OR_GOTO ("gsync", master, out);
GF_VALIDATE_OR_GOTO ("gsync", slave, out);
- snprintf (temp_conf_path, sizeof(temp_conf_path) - 1,
- "%s/"GSYNC_CONF_TEMPLATE, priv->workdir);
+ len = snprintf (temp_conf_path, sizeof(temp_conf_path),
+ "%s/"GSYNC_CONF_TEMPLATE, priv->workdir);
+ if ((len < 0) || (len >= sizeof(temp_conf_path))) {
+ goto out;
+ }
ret = sys_lstat (conf_path, &stbuf);
if (!ret) {
@@ -2417,6 +2421,7 @@ glusterd_op_stage_copy_file (dict_t *dict, char **op_errstr)
char workdir[PATH_MAX] = {0,};
char realpath_filename[PATH_MAX] = {0,};
char realpath_workdir[PATH_MAX] = {0,};
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2458,13 +2463,20 @@ glusterd_op_stage_copy_file (dict_t *dict, char **op_errstr)
*op_errstr = gf_strdup ("command unsuccessful");
goto out;
}
- snprintf (abs_filename, sizeof(abs_filename),
- "%s/%s", priv->workdir, filename);
+ len = snprintf (abs_filename, sizeof(abs_filename),
+ "%s/%s", priv->workdir, filename);
+ if ((len < 0) || (len >= sizeof(abs_filename))) {
+ ret = -1;
+ goto out;
+ }
if (!realpath (priv->workdir, realpath_workdir)) {
- snprintf (errmsg, sizeof (errmsg), "Failed to get "
- "realpath of %s: %s", priv->workdir,
- strerror (errno));
+ len = snprintf (errmsg, sizeof (errmsg), "Failed to "
+ "get realpath of %s: %s",
+ priv->workdir, strerror (errno));
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
ret = -1;
goto out;
@@ -2481,12 +2493,21 @@ glusterd_op_stage_copy_file (dict_t *dict, char **op_errstr)
/* Add Trailing slash to workdir, without slash strncmp
will succeed for /var/lib/glusterd_bad */
- snprintf (workdir, sizeof(workdir), "%s/", realpath_workdir);
+ len = snprintf (workdir, sizeof(workdir), "%s/",
+ realpath_workdir);
+ if ((len < 0) || (len >= sizeof(workdir))) {
+ ret = -1;
+ goto out;
+ }
/* Protect against file copy outside $workdir */
if (strncmp (workdir, realpath_filename, strlen (workdir))) {
- snprintf (errmsg, sizeof (errmsg), "Source file"
- " is outside of %s directory", priv->workdir);
+ len = snprintf (errmsg, sizeof (errmsg), "Source file"
+ " is outside of %s directory",
+ priv->workdir);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
ret = -1;
goto out;
@@ -2494,8 +2515,12 @@ glusterd_op_stage_copy_file (dict_t *dict, char **op_errstr)
ret = sys_lstat (abs_filename, &stbuf);
if (ret) {
- snprintf (errmsg, sizeof (errmsg), "Source file"
- " does not exist in %s", priv->workdir);
+ len = snprintf (errmsg, sizeof (errmsg), "Source file"
+ " does not exist in %s",
+ priv->workdir);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
goto out;
}
@@ -2532,6 +2557,7 @@ glusterd_get_statefile_name (glusterd_volinfo_t *volinfo, char *slave,
int ret = -1;
struct stat stbuf = {0,};
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2552,8 +2578,11 @@ glusterd_get_statefile_name (glusterd_volinfo_t *volinfo, char *slave,
priv = THIS->private;
- snprintf (temp_conf_path, sizeof(temp_conf_path) - 1,
- "%s/"GSYNC_CONF_TEMPLATE, priv->workdir);
+ len = snprintf (temp_conf_path, sizeof(temp_conf_path),
+ "%s/"GSYNC_CONF_TEMPLATE, priv->workdir);
+ if ((len < 0) || (len >= sizeof(temp_conf_path))) {
+ goto out;
+ }
ret = sys_lstat (conf_path, &stbuf);
if (!ret) {
@@ -3028,6 +3057,7 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr)
char *slave_user = NULL;
char *save_ptr = NULL;
char *slave_url_buf = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -3157,23 +3187,33 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr)
ret = dict_get_int32 (dict, "push_pem", &is_pem_push);
if (!ret && is_pem_push) {
ret = snprintf (common_pem_file,
- sizeof(common_pem_file) - 1,
+ sizeof(common_pem_file),
"%s"GLUSTERD_COMMON_PEM_PUB_FILE,
conf->workdir);
- common_pem_file[ret] = '\0';
+ if ((ret < 0) || (ret >= sizeof(common_pem_file))) {
+ ret = -1;
+ goto out;
+ }
- ret = snprintf (hook_script, sizeof(hook_script) - 1,
+ ret = snprintf (hook_script, sizeof(hook_script),
"%s"GLUSTERD_CREATE_HOOK_SCRIPT,
conf->workdir);
- hook_script[ret] = '\0';
+ if ((ret < 0) || (ret >= sizeof(hook_script))) {
+ ret = -1;
+ goto out;
+ }
ret = sys_lstat (common_pem_file, &stbuf);
if (ret) {
- snprintf (errmsg, sizeof (errmsg), "%s"
- " required for push-pem is"
- " not present. Please run"
- " \"gluster system:: execute"
- " gsec_create\"", common_pem_file);
+ len = snprintf (errmsg, sizeof (errmsg), "%s"
+ " required for push-pem is"
+ " not present. Please run"
+ " \"gluster system:: execute"
+ " gsec_create\"",
+ common_pem_file);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
gf_msg (this->name, GF_LOG_ERROR, ENOENT,
GD_MSG_FILE_OP_FAILED,
"%s", errmsg);
@@ -3184,11 +3224,15 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr)
ret = sys_lstat (hook_script, &stbuf);
if (ret) {
- snprintf (errmsg, sizeof (errmsg),
- "The hook-script (%s) required "
- "for push-pem is not present. "
- "Please install the hook-script "
- "and retry", hook_script);
+ len = snprintf (errmsg, sizeof (errmsg),
+ "The hook-script (%s) "
+ "required for push-pem is not "
+ "present. Please install the "
+ "hook-script and retry",
+ hook_script);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
gf_msg (this->name, GF_LOG_ERROR, ENOENT,
GD_MSG_FILE_OP_FAILED, "%s", errmsg);
*op_errstr = gf_strdup (errmsg);
@@ -3197,11 +3241,15 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr)
}
if (!S_ISREG(stbuf.st_mode)) {
- snprintf (errmsg, sizeof (errmsg), "%s"
- " required for push-pem is"
- " not a regular file. Please run"
- " \"gluster system:: execute"
- " gsec_create\"", common_pem_file);
+ len = snprintf (errmsg, sizeof (errmsg), "%s"
+ " required for push-pem is"
+ " not a regular file. Please"
+ " run \"gluster system:: "
+ "execute gsec_create\"",
+ common_pem_file);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
gf_msg (this->name, GF_LOG_ERROR, 0,
GD_MSG_REG_FILE_MISSING, "%s", errmsg);
ret = -1;
@@ -3314,16 +3362,23 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr)
/* Do the check, only if different slave host/slave user */
if (is_different_slavehost || is_different_username) {
- (void) snprintf (old_confpath, sizeof(old_confpath) - 1,
- "%s/"GEOREP"/%s_%s_%s/gsyncd.conf",
- conf->workdir, volinfo->volname,
- slave1.old_slvhost, slave_vol);
+ len = snprintf (old_confpath, sizeof(old_confpath),
+ "%s/"GEOREP"/%s_%s_%s/gsyncd.conf",
+ conf->workdir, volinfo->volname,
+ slave1.old_slvhost, slave_vol);
+ if ((len < 0) || (len >= sizeof(old_confpath))) {
+ ret = -1;
+ goto out;
+ }
/* construct old slave url with (old) slave host */
- (void) snprintf (old_slave_url,
- sizeof(old_slave_url) - 1,
- "%s::%s", slave1.old_slvhost,
- slave_vol);
+ len = snprintf (old_slave_url, sizeof(old_slave_url),
+ "%s::%s", slave1.old_slvhost,
+ slave_vol);
+ if ((len < 0) || (len >= sizeof(old_slave_url))) {
+ ret = -1;
+ goto out;
+ }
ret = glusterd_check_gsync_running_local (volinfo->volname,
old_slave_url, old_confpath, &is_running);
@@ -4450,6 +4505,7 @@ glusterd_read_status_file (glusterd_volinfo_t *volinfo, char *slave,
glusterd_conf_t *priv = NULL;
struct stat stbuf = {0,};
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -4469,8 +4525,11 @@ glusterd_read_status_file (glusterd_volinfo_t *volinfo, char *slave,
priv = THIS->private;
- snprintf (temp_conf_path, sizeof(temp_conf_path) - 1,
- "%s/"GSYNC_CONF_TEMPLATE, priv->workdir);
+ len = snprintf (temp_conf_path, sizeof(temp_conf_path),
+ "%s/"GSYNC_CONF_TEMPLATE, priv->workdir);
+ if ((len < 0) || (len >= sizeof(temp_conf_path))) {
+ return -1;
+ }
ret = sys_lstat (conf_path, &stbuf);
if (!ret) {
@@ -5296,6 +5355,7 @@ glusterd_op_copy_file (dict_t *dict, char **op_errstr)
struct stat stbuf = {0,};
gf_boolean_t free_contents = _gf_true;
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -5321,15 +5381,22 @@ glusterd_op_copy_file (dict_t *dict, char **op_errstr)
*op_errstr = gf_strdup ("command unsuccessful");
goto out;
}
- snprintf (abs_filename, sizeof(abs_filename),
- "%s/%s", priv->workdir, filename);
+ len = snprintf (abs_filename, sizeof(abs_filename),
+ "%s/%s", priv->workdir, filename);
+ if ((len < 0) || (len >= sizeof(abs_filename))) {
+ ret = -1;
+ goto out;
+ }
uuid_utoa_r (MY_UUID, uuid_str);
if (!strcmp (uuid_str, host_uuid)) {
ret = sys_lstat (abs_filename, &stbuf);
if (ret) {
- snprintf (errmsg, sizeof (errmsg), "Source file"
- " does not exist in %s", priv->workdir);
+ len = snprintf (errmsg, sizeof (errmsg), "Source file "
+ "does not exist in %s", priv->workdir);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, ENOENT,
GD_MSG_FILE_OP_FAILED, "%s", errmsg);
@@ -5350,8 +5417,11 @@ glusterd_op_copy_file (dict_t *dict, char **op_errstr)
fd = open (abs_filename, O_RDONLY);
if (fd < 0) {
- snprintf (errmsg, sizeof (errmsg), "Unable to open %s",
- abs_filename);
+ len = snprintf (errmsg, sizeof (errmsg),
+ "Unable to open %s", abs_filename);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, 0,
GD_MSG_FILE_OP_FAILED,
@@ -5370,8 +5440,12 @@ glusterd_op_copy_file (dict_t *dict, char **op_errstr)
} while (ret > 0);
if (bytes_read != stbuf.st_size) {
- snprintf (errmsg, sizeof (errmsg), "Unable to read all "
- "the data from %s", abs_filename);
+ len = snprintf (errmsg, sizeof (errmsg),
+ "Unable to read all the data from %s",
+ abs_filename);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_READ_ERROR,
"%s", errmsg);
@@ -5446,8 +5520,11 @@ glusterd_op_copy_file (dict_t *dict, char **op_errstr)
fd = open (abs_filename, O_WRONLY | O_TRUNC | O_CREAT, 0600);
if (fd < 0) {
- snprintf (errmsg, sizeof (errmsg), "Unable to open %s",
- abs_filename);
+ len = snprintf (errmsg, sizeof (errmsg),
+ "Unable to open %s", abs_filename);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, 0,
GD_MSG_FILE_OP_FAILED, "%s", errmsg);
@@ -5458,8 +5535,11 @@ glusterd_op_copy_file (dict_t *dict, char **op_errstr)
bytes_writen = sys_write (fd, contents, contents_size);
if (bytes_writen != contents_size) {
- snprintf (errmsg, sizeof (errmsg), "Failed to write"
- " to %s", abs_filename);
+ len = snprintf (errmsg, sizeof (errmsg),
+ "Failed to write to %s", abs_filename);
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, 0,
GD_MSG_FILE_OP_FAILED, "%s", errmsg);
@@ -6174,6 +6254,7 @@ glusterd_create_essential_dir_files (glusterd_volinfo_t *volinfo, dict_t *dict,
glusterd_conf_t *conf = NULL;
struct stat stbuf = {0,};
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -6198,13 +6279,19 @@ glusterd_create_essential_dir_files (glusterd_volinfo_t *volinfo, dict_t *dict,
goto out;
}
- ret = snprintf (buf, sizeof(buf) - 1, "%s/"GEOREP"/%s_%s_%s",
+ ret = snprintf (buf, sizeof(buf), "%s/"GEOREP"/%s_%s_%s",
conf->workdir, volinfo->volname, slave_host, slave_vol);
- buf[ret] = '\0';
+ if ((ret < 0) || (ret >= sizeof(buf))) {
+ ret = -1;
+ goto out;
+ }
ret = mkdir_p (buf, 0777, _gf_true);
if (ret) {
- snprintf (errmsg, sizeof (errmsg), "Unable to create %s"
- ". Error : %s", buf, strerror (errno));
+ len = snprintf (errmsg, sizeof (errmsg), "Unable to create %s"
+ ". Error : %s", buf, strerror (errno));
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
"%s", errmsg);
@@ -6213,11 +6300,17 @@ glusterd_create_essential_dir_files (glusterd_volinfo_t *volinfo, dict_t *dict,
ret = snprintf (buf, PATH_MAX, DEFAULT_LOG_FILE_DIRECTORY"/"GEOREP"/%s",
volinfo->volname);
- buf[ret] = '\0';
+ if ((ret < 0) || (ret >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
ret = mkdir_p (buf, 0777, _gf_true);
if (ret) {
- snprintf (errmsg, sizeof (errmsg), "Unable to create %s"
- ". Error : %s", buf, strerror (errno));
+ len = snprintf (errmsg, sizeof (errmsg), "Unable to create %s"
+ ". Error : %s", buf, strerror (errno));
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
*op_errstr = gf_strdup (errmsg);
gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
"%s", errmsg);
@@ -6294,6 +6387,7 @@ glusterd_op_gsync_create (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
char *slave_voluuid = NULL;
char *old_slavehost = NULL;
gf_boolean_t is_existing_session = _gf_false;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -6307,8 +6401,12 @@ glusterd_op_gsync_create (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
if (ret)
goto out;
- snprintf (common_pem_file, sizeof(common_pem_file),
- "%s"GLUSTERD_COMMON_PEM_PUB_FILE, conf->workdir);
+ len = snprintf (common_pem_file, sizeof(common_pem_file),
+ "%s"GLUSTERD_COMMON_PEM_PUB_FILE, conf->workdir);
+ if ((len < 0) || (len >= sizeof(common_pem_file))) {
+ ret = -1;
+ goto out;
+ }
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
@@ -6390,11 +6488,15 @@ glusterd_op_gsync_create (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
} else
is_pem_push = 0;
- snprintf(hooks_args, sizeof(hooks_args),
- "is_push_pem=%d,pub_file=%s,slave_user=%s,slave_ip=%s,"
- "slave_vol=%s,ssh_port=%d", is_pem_push,
- common_pem_file, slave_user, slave_ip, slave_vol,
- ssh_port);
+ len = snprintf(hooks_args, sizeof(hooks_args),
+ "is_push_pem=%d,pub_file=%s,slave_user=%s,"
+ "slave_ip=%s,slave_vol=%s,ssh_port=%d",
+ is_pem_push, common_pem_file, slave_user,
+ slave_ip, slave_vol, ssh_port);
+ if ((len < 0) || (len >= sizeof(hooks_args))) {
+ ret = -1;
+ goto out;
+ }
} else
snprintf(hooks_args, sizeof(hooks_args),
"This argument will stop the hooks script");
@@ -6477,11 +6579,16 @@ create_essentials:
"not present.",
old_working_dir);
} else {
- snprintf (errmsg, sizeof (errmsg),
- "rename of old working dir %s to "
- "new working dir %s failed! Error: %s",
- old_working_dir, new_working_dir,
- strerror (errno));
+ len = snprintf (errmsg, sizeof (errmsg),
+ "rename of old working dir %s "
+ "to new working dir %s "
+ "failed! Error: %s",
+ old_working_dir,
+ new_working_dir,
+ strerror (errno));
+ if (len < 0) {
+ strcpy(errmsg, "<error>");
+ }
gf_msg (this->name, GF_LOG_INFO, 0,
GD_MSG_FORCE_CREATE_SESSION,
"rename of old working dir %s to "
diff --git a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c
index 2949297788f..7098ae27eaf 100644
--- a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c
+++ b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c
@@ -33,10 +33,14 @@ glusterd_svc_build_gfproxyd_socket_filepath (glusterd_volinfo_t *volinfo,
{
char sockfilepath[PATH_MAX] = {0,};
char rundir[PATH_MAX] = {0,};
+ int32_t len = 0;
glusterd_svc_build_gfproxyd_rundir (volinfo, rundir, sizeof (rundir));
- snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
- rundir, uuid_utoa (MY_UUID));
+ len = snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
+ rundir, uuid_utoa (MY_UUID));
+ if ((len < 0) || (len >= sizeof(sockfilepath))) {
+ sockfilepath[0] = 0;
+ }
glusterd_set_socket_filepath (sockfilepath, path, path_len);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c
index c0b96b10995..9ac649db60d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c
+++ b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c
@@ -62,6 +62,7 @@ int glusterd_gfproxydsvc_init (glusterd_volinfo_t *volinfo)
glusterd_conn_notify_t notify = NULL;
xlator_t *this = NULL;
char *volfileserver = NULL;
+ int32_t len = 0;
this = THIS;
GF_VALIDATE_OR_GOTO ("glusterd", this, out);
@@ -101,7 +102,12 @@ int glusterd_gfproxydsvc_init (glusterd_volinfo_t *volinfo)
goto out;
}
glusterd_svc_build_gfproxyd_logfile (logfile, logdir, sizeof (logfile));
- snprintf (volfileid, sizeof (volfileid), "gfproxyd/%s", volinfo->volname);
+ len = snprintf (volfileid, sizeof (volfileid), "gfproxyd/%s",
+ volinfo->volname);
+ if ((len < 0) || (len >= sizeof(volfileid))) {
+ ret = -1;
+ goto out;
+ }
if (dict_get_str (this->options, "transport.socket.bind-address",
&volfileserver) != 0) {
@@ -264,6 +270,7 @@ glusterd_gfproxydsvc_start (glusterd_svc_t *svc, int flags)
char gfproxyd_id[PATH_MAX] = {0,};
glusterd_volinfo_t *volinfo = NULL;
char *localtime_logging = NULL;
+ int32_t len = 0;
this = THIS;
GF_VALIDATE_OR_GOTO ("glusterd", this, out);
@@ -292,8 +299,12 @@ glusterd_gfproxydsvc_start (glusterd_svc_t *svc, int flags)
runinit (&runner);
if (this->ctx->cmd_args.valgrind) {
- snprintf (valgrind_logfile, PATH_MAX, "%s/valgrind-%s",
- svc->proc.logdir, svc->proc.logfile);
+ len = snprintf (valgrind_logfile, PATH_MAX, "%s/valgrind-%s",
+ svc->proc.logdir, svc->proc.logfile);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
runner_add_args (&runner, "valgrind", "--leak-check=full",
"--trace-children=yes", "--track-origins=yes",
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index dd81887ed1f..b59d3819d95 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -471,6 +471,7 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,
struct args_pack pack = {0,};
xlator_t *this = NULL;
GF_UNUSED int caps = 0;
+ int32_t len = 0;
GF_ASSERT (volinfo);
GF_ASSERT (volumes);
@@ -654,8 +655,12 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,
char brick[1024] = {0,};
char brick_uuid[64] = {0,};
snprintf (key, 256, "volume%d.brick%d", count, i);
- snprintf (brick, 1024, "%s:%s", brickinfo->hostname,
- brickinfo->path);
+ len = snprintf (brick, 1024, "%s:%s", brickinfo->hostname,
+ brickinfo->path);
+ if ((len < 0) || (len >= 1024)) {
+ ret = -1;
+ goto out;
+ }
buf = gf_strdup (brick);
ret = dict_set_dynstr (volumes, key, buf);
if (ret)
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
index 84dd077af73..35b6bed409e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
@@ -196,6 +196,7 @@ build_volfile_path (char *volume_id, char *path,
xlator_t *this = NULL;
glusterd_volinfo_t *volinfo = NULL;
glusterd_conf_t *priv = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -321,13 +322,18 @@ build_volfile_path (char *volume_id, char *path,
goto out;
}
- snprintf (path_prefix, sizeof (path_prefix), "%s/snaps/%s",
- priv->workdir, volinfo->snapshot->snapname);
-
+ len = snprintf (path_prefix, sizeof (path_prefix),
+ "%s/snaps/%s", priv->workdir,
+ volinfo->snapshot->snapname);
volid_ptr = volname;
/* this is to ensure that volname recvd from
get_snap_volname_and_volinfo is free'd */
free_ptr = volname;
+ if ((len < 0) || (len >= sizeof(path_prefix))) {
+ ret = -1;
+ goto out;
+ }
+
goto gotvolinfo;
}
@@ -408,8 +414,12 @@ build_volfile_path (char *volume_id, char *path,
volid_ptr = volume_id;
}
- snprintf (path_prefix, sizeof (path_prefix), "%s/vols",
- priv->workdir);
+ len = snprintf (path_prefix, sizeof (path_prefix), "%s/vols",
+ priv->workdir);
+ if ((len < 0) || (len >= sizeof(path_prefix))) {
+ ret = -1;
+ goto out;
+ }
ret = glusterd_volinfo_find (volid_ptr, &volinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c
index b310bc2a109..914d029ed39 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c
@@ -80,6 +80,7 @@ glusterd_hooks_create_hooks_directory (char *basedir)
"pre",
"post"};
glusterd_conf_t *priv = NULL;
+ int32_t len = 0;
priv = THIS->private;
@@ -106,8 +107,12 @@ glusterd_hooks_create_hooks_directory (char *basedir)
if (strlen (cmd_subdir) == 0)
continue;
- snprintf (path, sizeof (path), "%s/%s", version_dir,
- cmd_subdir);
+ len = snprintf (path, sizeof (path), "%s/%s", version_dir,
+ cmd_subdir);
+ if ((len < 0) || (len >= sizeof(path))) {
+ ret = -1;
+ goto out;
+ }
ret = mkdir_p (path, 0777, _gf_true);
if (ret) {
gf_msg (THIS->name, GF_LOG_CRITICAL, errno,
@@ -119,8 +124,13 @@ glusterd_hooks_create_hooks_directory (char *basedir)
for (type = GD_COMMIT_HOOK_PRE; type < GD_COMMIT_HOOK_MAX;
type++) {
- snprintf (path, sizeof (path), "%s/%s/%s",
- version_dir, cmd_subdir, type_subdir[type]);
+ len = snprintf (path, sizeof (path), "%s/%s/%s",
+ version_dir, cmd_subdir,
+ type_subdir[type]);
+ if ((len < 0) || (len >= sizeof(path))) {
+ ret = -1;
+ goto out;
+ }
ret = mkdir_p (path, 0777, _gf_true);
if (ret) {
gf_msg (THIS->name, GF_LOG_CRITICAL, errno,
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.h b/xlators/mgmt/glusterd/src/glusterd-hooks.h
index 7bab6adb626..752e459f89c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.h
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.h
@@ -13,8 +13,14 @@
#include <fnmatch.h>
#define GLUSTERD_GET_HOOKS_DIR(path, version, priv) \
- snprintf (path, PATH_MAX, "%s/hooks/%d", priv->workdir,\
- version);
+ do { \
+ int32_t len; \
+ len = snprintf (path, PATH_MAX, "%s/hooks/%d", priv->workdir,\
+ version); \
+ if (len < 0) { \
+ path[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_HOOK_VER 1
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
index 33d5de45cd5..5b7d782a1e6 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
@@ -41,6 +41,7 @@ gd_mgmt_v3_collate_errors (struct syncargs *args, int op_ret, int op_errno,
int is_operrstr_blk = 0;
char *err_string = NULL;
glusterd_peerinfo_t *peerinfo = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -113,8 +114,11 @@ gd_mgmt_v3_collate_errors (struct syncargs *args, int op_ret, int op_errno,
}
if (args->errstr) {
- snprintf (err_str, sizeof(err_str),
- "%s\n%s", args->errstr, op_err);
+ len = snprintf (err_str, sizeof(err_str),
+ "%s\n%s", args->errstr, op_err);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
GF_FREE (args->errstr);
args->errstr = NULL;
} else
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index e49b9c720e5..a19d98a51c2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -790,6 +790,7 @@ glusterd_validate_shared_storage (char *key, char *value, char *errstr)
char hook_script[PATH_MAX] = "";
xlator_t *this = NULL;
glusterd_conf_t *conf = NULL;
+ int32_t len = 0;
this = THIS;
GF_VALIDATE_OR_GOTO ("glusterd", this, out);
@@ -818,16 +819,23 @@ glusterd_validate_shared_storage (char *key, char *value, char *errstr)
goto out;
}
- snprintf (hook_script, sizeof(hook_script),
- "%s"GLUSTERD_SHRD_STRG_HOOK_SCRIPT, conf->workdir);
+ len = snprintf (hook_script, sizeof(hook_script),
+ "%s"GLUSTERD_SHRD_STRG_HOOK_SCRIPT, conf->workdir);
+ if ((len < 0) || (len >= sizeof(hook_script))) {
+ ret = -1;
+ goto out;
+ }
ret = sys_access (hook_script, R_OK|X_OK);
if (ret) {
- snprintf (errstr, PATH_MAX,
- "The hook-script (%s) required "
- "for this operation is not present. "
- "Please install the hook-script "
- "and retry", hook_script);
+ len = snprintf (errstr, PATH_MAX,
+ "The hook-script (%s) required "
+ "for this operation is not present. "
+ "Please install the hook-script "
+ "and retry", hook_script);
+ if (len < 0) {
+ strncpy(errstr, "<error>", PATH_MAX);
+ }
gf_msg (this->name, GF_LOG_ERROR, ENOENT,
GD_MSG_FILE_OP_FAILED, "%s", errstr);
goto out;
@@ -2806,6 +2814,7 @@ glusterd_set_shared_storage (dict_t *dict, char *key, char *value,
char hooks_args[PATH_MAX] = {0, };
char errstr[PATH_MAX] = {0, };
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_VALIDATE_OR_GOTO ("glusterd", this, out);
@@ -2849,13 +2858,17 @@ glusterd_set_shared_storage (dict_t *dict, char *key, char *value,
}
if (is_origin_glusterd (dict)) {
- snprintf(hooks_args, sizeof(hooks_args),
- "is_originator=1,local_node_hostname=%s",
- local_node_hostname);
+ len = snprintf(hooks_args, sizeof(hooks_args),
+ "is_originator=1,local_node_hostname=%s",
+ local_node_hostname);
} else {
- snprintf(hooks_args, sizeof(hooks_args),
- "is_originator=0,local_node_hostname=%s",
- local_node_hostname);
+ len = snprintf(hooks_args, sizeof(hooks_args),
+ "is_originator=0,local_node_hostname=%s",
+ local_node_hostname);
+ }
+ if ((len < 0) || (len >= sizeof(hooks_args))) {
+ ret = -1;
+ goto out;
}
ret = dict_set_dynstr_with_alloc (dict, "hooks_args", hooks_args);
@@ -3402,6 +3415,7 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo,
char dict_key[1024] ={0,};
char *brick = NULL;
xlator_t *this = NULL;
+ int32_t len = 0;
GF_ASSERT (dict);
GF_ASSERT (volinfo);
@@ -3440,8 +3454,12 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo,
}
memset (dict_key, 0, sizeof (dict_key));
- snprintf (dict_key, sizeof (dict_key), "%s.%s", prefix,
- brick_key);
+ len = snprintf (dict_key, sizeof (dict_key), "%s.%s", prefix,
+ brick_key);
+ if ((len < 0) || (len >= sizeof(dict_key))) {
+ ret = -1;
+ goto out;
+ }
ret = dict_set_str (dict, dict_key, brick);
if (ret) {
gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -5300,9 +5318,10 @@ glusterd_op_commit_hook (glusterd_op_t op, dict_t *op_ctx,
glusterd_conf_t *priv = NULL;
char hookdir[PATH_MAX] = {0, };
char scriptdir[PATH_MAX] = {0, };
- char type_subdir[256] = {0, };
+ char *type_subdir = "";
char *cmd_subdir = NULL;
int ret = -1;
+ int32_t len = 0;
priv = THIS->private;
switch (type) {
@@ -5312,10 +5331,10 @@ glusterd_op_commit_hook (glusterd_op_t op, dict_t *op_ctx,
break;
case GD_COMMIT_HOOK_PRE:
- strcpy (type_subdir, "pre");
+ type_subdir = "pre";
break;
case GD_COMMIT_HOOK_POST:
- strcpy (type_subdir, "post");
+ type_subdir = "post";
break;
}
@@ -5324,8 +5343,11 @@ glusterd_op_commit_hook (glusterd_op_t op, dict_t *op_ctx,
return -1;
GLUSTERD_GET_HOOKS_DIR (hookdir, GLUSTERD_HOOK_VER, priv);
- snprintf (scriptdir, sizeof (scriptdir), "%s/%s/%s",
- hookdir, cmd_subdir, type_subdir);
+ len = snprintf (scriptdir, sizeof (scriptdir), "%s/%s/%s",
+ hookdir, cmd_subdir, type_subdir);
+ if ((len < 0) || (len >= sizeof(scriptdir))) {
+ return -1;
+ }
switch (type) {
case GD_COMMIT_HOOK_NONE:
@@ -6981,7 +7003,7 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo,
dict_t *req_dict)
{
glusterd_brickinfo_t *brickinfo = NULL;
- char msg[1024] = {0,};
+ char *msg = "self-heal-daemon is not running on";
char key[1024] = {0,};
char value[1024] = {0,};
int ret = 0;
@@ -6989,7 +7011,6 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo,
int cmd_replica_index = -1;
this = THIS;
- snprintf (msg, sizeof (msg), "self-heal-daemon is not running on");
if (type == PER_HEAL_XL) {
cmd_replica_index = get_replica_index_for_per_replica_cmd
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
index 6231fe3a7f4..847c1a721d0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
@@ -249,6 +249,7 @@ _glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv,
runner_t runner = {0};
char *volfileserver = NULL;
FILE *pidfp = NULL;
+ int32_t len = 0;
GF_VALIDATE_OR_GOTO ("glusterd", THIS, out);
@@ -272,16 +273,25 @@ _glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv,
}
GLUSTERD_REMOVE_SLASH_FROM_PATH (brick->path, brickpath);
- snprintf (logfile, sizeof (logfile),
- DEFAULT_QUOTA_CRAWL_LOG_DIRECTORY"/%s.log",
- brickpath);
+ len = snprintf (logfile, sizeof (logfile),
+ DEFAULT_QUOTA_CRAWL_LOG_DIRECTORY"/%s.log",
+ brickpath);
+ if ((len < 0) || (len >= sizeof(vol_id))) {
+ ret = -1;
+ goto out;
+ }
if (dict_get_str (THIS->options, "transport.socket.bind-address",
&volfileserver) != 0)
volfileserver = "localhost";
- snprintf (vol_id, sizeof (vol_id), "client_per_brick/%s.%s.%s.%s.vol",
- volinfo->volname, "client", brick->hostname, brickpath);
+ len = snprintf (vol_id, sizeof (vol_id),
+ "client_per_brick/%s.%s.%s.%s.vol", volinfo->volname,
+ "client", brick->hostname, brickpath);
+ if ((len < 0) || (len >= sizeof(vol_id))) {
+ ret = -1;
+ goto out;
+ }
runinit (&runner);
@@ -370,13 +380,15 @@ _glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv,
_exit (EXIT_FAILURE);
}
- snprintf (pidfile, sizeof (pidfile), "%s/%s.pid", pid_dir,
- brickpath);
- pidfp = fopen (pidfile, "w");
- if (pidfp) {
- fprintf (pidfp, "%d\n", runner.chpid);
- fflush (pidfp);
- fclose (pidfp);
+ len = snprintf (pidfile, sizeof (pidfile), "%s/%s.pid",
+ pid_dir, brickpath);
+ if ((len >= 0) && (len < sizeof(pidfile))) {
+ pidfp = fopen (pidfile, "w");
+ if (pidfp >= 0) {
+ fprintf (pidfp, "%d\n", runner.chpid);
+ fflush (pidfp);
+ fclose (pidfp);
+ }
}
#ifndef GF_LINUX_HOST_OS
@@ -402,6 +414,7 @@ glusterd_stop_all_quota_crawl_service (glusterd_conf_t *priv,
struct dirent scratch[2] = {{0,},};
char pid_dir[PATH_MAX] = {0,};
char pidfile[PATH_MAX] = {0,};
+ int32_t len = 0;
GLUSTERD_GET_QUOTA_CRAWL_PIDDIR (pid_dir, volinfo, type);
@@ -411,12 +424,13 @@ glusterd_stop_all_quota_crawl_service (glusterd_conf_t *priv,
GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch);
while (entry) {
- snprintf (pidfile, sizeof (pidfile), "%s/%s",
- pid_dir, entry->d_name);
-
- glusterd_service_stop_nolock ("quota_crawl", pidfile, SIGKILL,
- _gf_true);
- sys_unlink (pidfile);
+ len = snprintf (pidfile, sizeof (pidfile), "%s/%s",
+ pid_dir, entry->d_name);
+ if ((len >= 0) && (len < sizeof(pidfile))) {
+ glusterd_service_stop_nolock ("quota_crawl", pidfile,
+ SIGKILL, _gf_true);
+ sys_unlink (pidfile);
+ }
GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-snapd-svc-helper.c
index b2e06825c32..8f1630f1871 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapd-svc-helper.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapd-svc-helper.c
@@ -29,10 +29,14 @@ glusterd_svc_build_snapd_socket_filepath (glusterd_volinfo_t *volinfo,
{
char sockfilepath[PATH_MAX] = {0,};
char rundir[PATH_MAX] = {0,};
+ int32_t len = 0;
glusterd_svc_build_snapd_rundir (volinfo, rundir, sizeof (rundir));
- snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
- rundir, uuid_utoa (MY_UUID));
+ len = snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
+ rundir, uuid_utoa (MY_UUID));
+ if ((len < 0) || (len >= sizeof(sockfilepath))) {
+ sockfilepath[0] = 0;
+ }
glusterd_set_socket_filepath (sockfilepath, path, path_len);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
index c32a081156e..3c713291f91 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
@@ -62,6 +62,7 @@ glusterd_snapdsvc_init (void *data)
glusterd_conn_notify_t notify = NULL;
xlator_t *this = NULL;
char *volfileserver = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -102,7 +103,12 @@ glusterd_snapdsvc_init (void *data)
goto out;
}
glusterd_svc_build_snapd_logfile (logfile, logdir, sizeof (logfile));
- snprintf (volfileid, sizeof (volfileid), "snapd/%s", volinfo->volname);
+ len = snprintf (volfileid, sizeof (volfileid), "snapd/%s",
+ volinfo->volname);
+ if ((len < 0) || (len >= sizeof(volfileid))) {
+ ret = -1;
+ goto out;
+ }
if (dict_get_str (this->options, "transport.socket.bind-address",
&volfileserver) != 0) {
@@ -227,6 +233,7 @@ glusterd_snapdsvc_start (glusterd_svc_t *svc, int flags)
glusterd_volinfo_t *volinfo = NULL;
glusterd_snapdsvc_t *snapd = NULL;
char *localtime_logging = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT(this);
@@ -282,8 +289,12 @@ glusterd_snapdsvc_start (glusterd_svc_t *svc, int flags)
runinit (&runner);
if (this->ctx->cmd_args.valgrind) {
- snprintf (valgrind_logfile, PATH_MAX, "%s/valgrind-snapd.log",
- svc->proc.logdir);
+ len = snprintf (valgrind_logfile, PATH_MAX,
+ "%s/valgrind-snapd.log", svc->proc.logdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
runner_add_args (&runner, "valgrind", "--leak-check=full",
"--trace-children=yes", "--track-origins=yes",
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
index 340289f74e8..249d99ea3dd 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
@@ -669,8 +669,8 @@ int32_t
glusterd_add_snap_to_dict (glusterd_snap_t *snap, dict_t *peer_data,
int32_t snap_count)
{
- char buf[NAME_MAX] = "";
- char prefix[NAME_MAX] = "";
+ char buf[64] = "";
+ char prefix[32] = "";
int32_t ret = -1;
int32_t volcount = 0;
glusterd_volinfo_t *volinfo = NULL;
@@ -1551,8 +1551,8 @@ int32_t
glusterd_import_friend_snap (dict_t *peer_data, int32_t snap_count,
char *peer_snap_name, char *peer_snap_id)
{
- char buf[NAME_MAX] = "";
- char prefix[NAME_MAX] = "";
+ char buf[64] = "";
+ char prefix[32] = "";
dict_t *dict = NULL;
glusterd_snap_t *snap = NULL;
glusterd_volinfo_t *snap_vol = NULL;
@@ -1792,8 +1792,8 @@ int32_t
glusterd_compare_snap (dict_t *peer_data, int32_t snap_count,
char *peername, uuid_t peerid)
{
- char buf[NAME_MAX] = "";
- char prefix[NAME_MAX] = "";
+ char buf[64] = "";
+ char prefix[32] = "";
char *peer_snap_name = NULL;
char *peer_snap_id = NULL;
glusterd_snap_t *snap = NULL;
@@ -1994,8 +1994,8 @@ glusterd_update_snaps_synctask (void *opaque)
int i = 1;
xlator_t *this = NULL;
dict_t *peer_data = NULL;
- char buf[NAME_MAX] = "";
- char prefix[NAME_MAX] = "";
+ char buf[64] = "";
+ char prefix[32] = "";
char *peer_snap_name = NULL;
char *peer_snap_id = NULL;
char *peername = NULL;
@@ -2205,8 +2205,8 @@ glusterd_add_snapd_to_dict (glusterd_volinfo_t *volinfo,
int ret = -1;
int32_t pid = -1;
int32_t brick_online = -1;
- char key[1024] = {0};
- char base_key[1024] = {0};
+ char key[64] = {0};
+ char base_key[32] = {0};
char pidfile[PATH_MAX] = {0};
xlator_t *this = NULL;
@@ -2433,8 +2433,8 @@ glusterd_merge_brick_status (dict_t *dst, dict_t *src)
int64_t j = 0;
int64_t brick_count = 0;
int64_t brick_order = 0;
- char key[PATH_MAX] = {0, };
- char key_prefix[PATH_MAX] = {0, };
+ char key[64] = {0, };
+ char key_prefix[16] = {0, };
char snapbrckcnt[PATH_MAX] = {0, };
char snapbrckord[PATH_MAX] = {0, };
char *clonename = NULL;
@@ -2510,7 +2510,7 @@ glusterd_merge_brick_status (dict_t *dst, dict_t *src)
goto out;
}
- snprintf (key, sizeof (key) - 1,
+ snprintf (key, sizeof (key),
"%s%"PRId64".brick%"PRId64".status",
key_prefix, index+1, brick_order);
ret = dict_get_int32 (src, key, &brick_online);
@@ -2852,6 +2852,7 @@ glusterd_mount_lvm_snapshot (glusterd_brickinfo_t *brickinfo,
int32_t ret = -1;
runner_t runner = {0, };
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2860,8 +2861,11 @@ glusterd_mount_lvm_snapshot (glusterd_brickinfo_t *brickinfo,
runinit (&runner);
- snprintf (msg, sizeof (msg), "mount %s %s",
- brickinfo->device_path, brick_mount_path);
+ len = snprintf (msg, sizeof (msg), "mount %s %s",
+ brickinfo->device_path, brick_mount_path);
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
gf_strncpy (mnt_opts, brickinfo->mnt_opts, sizeof(mnt_opts));
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 4a4c379cd86..4be89779465 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -280,8 +280,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
count);
ret = dict_set_str (rsp_dict, buf, volinfo->volname);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -289,8 +292,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
"volume%"PRId64"-snap-max-hard-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, snap_max_limit);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -299,8 +305,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
ret = dict_set_uint64 (rsp_dict, buf,
active_hard_limit);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -308,8 +317,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
"volume%"PRId64"-snap-max-soft-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
count++;
@@ -342,8 +354,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
snprintf (buf, sizeof(buf), "volume%"PRId64"-volname", count);
ret = dict_set_str (rsp_dict, buf, volinfo->volname);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -351,8 +366,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
"volume%"PRId64"-snap-max-hard-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, snap_max_limit);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -360,8 +378,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
"volume%"PRId64"-active-hard-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, active_hard_limit);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -369,8 +390,11 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
"volume%"PRId64"-snap-max-soft-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value);
if (ret) {
- snprintf (err_str, PATH_MAX,
- "Failed to set %s", buf);
+ len = snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
goto out;
}
@@ -605,6 +629,7 @@ glusterd_snapshot_backup_vol (glusterd_volinfo_t *volinfo)
char trashdir[PATH_MAX] = {0,};
glusterd_conf_t *priv = NULL;
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -614,12 +639,18 @@ glusterd_snapshot_backup_vol (glusterd_volinfo_t *volinfo)
GLUSTERD_GET_VOLUME_DIR (pathname, volinfo, priv);
- snprintf (delete_path, sizeof (delete_path),
- "%s/"GLUSTERD_TRASH"/vols-%s.deleted", priv->workdir,
- volinfo->volname);
+ len = snprintf (delete_path, sizeof (delete_path),
+ "%s/"GLUSTERD_TRASH"/vols-%s.deleted", priv->workdir,
+ volinfo->volname);
+ if ((len < 0) || (len >= sizeof(delete_path))) {
+ goto out;
+ }
- snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH,
- priv->workdir);
+ len = snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH,
+ priv->workdir);
+ if ((len < 0) || (len >= sizeof(delete_path))) {
+ goto out;
+ }
/* Create trash folder if it is not there */
ret = sys_mkdir (trashdir, 0777);
@@ -2110,6 +2141,7 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags,
xlator_t *this = NULL;
glusterd_conf_t *conf = NULL;
glusterd_brickinfo_t *brickinfo = NULL;
+ int32_t len = 0;
this = THIS;
conf = this->private;
@@ -2170,10 +2202,13 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags,
orig_device = glusterd_get_brick_mount_device
(brickinfo->path);
if (!orig_device) {
- snprintf (err_str, PATH_MAX,
- "getting device name for the brick "
- "%s:%s failed", brickinfo->hostname,
- brickinfo->path);
+ len = snprintf (err_str, PATH_MAX,
+ "getting device name for the brick "
+ "%s:%s failed", brickinfo->hostname,
+ brickinfo->path);
+ if (len < 0) {
+ strcpy(err_str, "<error>");
+ }
ret = -1;
goto out;
}
@@ -2746,6 +2781,7 @@ glusterd_do_lvm_snapshot_remove (glusterd_volinfo_t *snap_vol,
int retry_count = 0;
char *mnt_pt = NULL;
gf_boolean_t unmount = _gf_true;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2834,9 +2870,12 @@ glusterd_do_lvm_snapshot_remove (glusterd_volinfo_t *snap_vol,
}
runinit (&runner);
- snprintf (msg, sizeof(msg), "remove snapshot of the brick %s:%s, "
- "device: %s", brickinfo->hostname, brickinfo->path,
- snap_device);
+ len = snprintf (msg, sizeof(msg), "remove snapshot of the brick %s:%s, "
+ "device: %s", brickinfo->hostname, brickinfo->path,
+ snap_device);
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
runner_add_args (&runner, LVM_REMOVE, "-f", snap_device, NULL);
runner_log (&runner, "", GF_LOG_DEBUG, msg);
@@ -4612,6 +4651,7 @@ glusterd_add_missed_snaps_to_dict (dict_t *rsp_dict,
int32_t missed_snap_count = -1;
int32_t ret = -1;
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -4625,10 +4665,13 @@ glusterd_add_missed_snaps_to_dict (dict_t *rsp_dict,
goto out;
}
- snprintf (missed_snap_entry, sizeof(missed_snap_entry),
- "%s:%s=%s:%d:%s:%d:%d", uuid_utoa(brickinfo->uuid),
- snap_uuid, snap_vol->volname, brick_number, brickinfo->path,
- op, GD_MISSED_SNAP_PENDING);
+ len = snprintf (missed_snap_entry, sizeof(missed_snap_entry),
+ "%s:%s=%s:%d:%s:%d:%d", uuid_utoa(brickinfo->uuid),
+ snap_uuid, snap_vol->volname, brick_number,
+ brickinfo->path, op, GD_MISSED_SNAP_PENDING);
+ if ((len < 0) || (len >= sizeof(missed_snap_entry))) {
+ goto out;
+ }
/* Fetch the missed_snap_count from the dict */
ret = dict_get_int32 (rsp_dict, "missed_snap_count",
@@ -4767,6 +4810,7 @@ glusterd_snap_brick_create (glusterd_volinfo_t *snap_volinfo,
char snap_brick_mount_path[PATH_MAX] = "";
char clone_uuid[64] = "";
struct stat statbuf = {0, };
+ int32_t len = 0;
this = THIS;
@@ -4775,13 +4819,18 @@ glusterd_snap_brick_create (glusterd_volinfo_t *snap_volinfo,
if (clone) {
GLUSTERD_GET_UUID_NOHYPHEN(clone_uuid, snap_volinfo->volume_id);
- snprintf (snap_brick_mount_path, sizeof (snap_brick_mount_path),
- "%s/%s/brick%d", snap_mount_dir,
- clone_uuid, brick_count + 1);
+ len = snprintf (snap_brick_mount_path,
+ sizeof (snap_brick_mount_path),
+ "%s/%s/brick%d", snap_mount_dir, clone_uuid,
+ brick_count + 1);
} else {
- snprintf (snap_brick_mount_path, sizeof (snap_brick_mount_path),
- "%s/%s/brick%d", snap_mount_dir,
- snap_volinfo->volname, brick_count + 1);
+ len = snprintf (snap_brick_mount_path,
+ sizeof (snap_brick_mount_path),
+ "%s/%s/brick%d", snap_mount_dir,
+ snap_volinfo->volname, brick_count + 1);
+ }
+ if ((len < 0) || (len >= sizeof(snap_brick_mount_path))) {
+ goto out;
}
ret = mkdir_p (snap_brick_mount_path, 0777, _gf_true);
@@ -4864,6 +4913,7 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict,
int32_t ret = -1;
xlator_t *this = NULL;
char abspath[PATH_MAX] = {0};
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -4978,15 +5028,19 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict,
*/
if (clone) {
GLUSTERD_GET_UUID_NOHYPHEN(clone_uuid, snap_vol->volume_id);
- snprintf (snap_brick_path, sizeof(snap_brick_path),
- "%s/%s/brick%d%s", snap_mount_dir,
- clone_uuid, brick_count+1,
- snap_brick_dir);
+ len = snprintf (snap_brick_path, sizeof(snap_brick_path),
+ "%s/%s/brick%d%s", snap_mount_dir,
+ clone_uuid, brick_count+1,
+ snap_brick_dir);
} else {
- snprintf (snap_brick_path, sizeof(snap_brick_path),
- "%s/%s/brick%d%s", snap_mount_dir,
- snap_vol->volname, brick_count+1,
- snap_brick_dir);
+ len = snprintf (snap_brick_path, sizeof(snap_brick_path),
+ "%s/%s/brick%d%s", snap_mount_dir,
+ snap_vol->volname, brick_count+1,
+ snap_brick_dir);
+ }
+ if ((len < 0) || (len >= sizeof(snap_brick_path))) {
+ ret = -1;
+ goto out;
}
snprintf (key, sizeof(key), "vol%"PRId64".brick_snapdevice%d",
@@ -5070,6 +5124,7 @@ glusterd_update_fs_label (glusterd_brickinfo_t *brickinfo)
uuid_t uuid = {0,};
runner_t runner = {0,};
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -5090,8 +5145,11 @@ glusterd_update_fs_label (glusterd_brickinfo_t *brickinfo)
/* XFS label is of size 12. Therefore we should truncate the
* label to 12 bytes*/
label [12] = '\0';
- snprintf (msg, sizeof (msg), "Changing filesystem label of "
- "%s brick to %s", brickinfo->path, label);
+ len = snprintf (msg, sizeof (msg), "Changing filesystem label "
+ "of %s brick to %s", brickinfo->path, label);
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
/* Run the run xfs_admin tool to change the label
* of the file-system */
runner_add_args (&runner, "xfs_admin", "-L", label,
@@ -5102,8 +5160,11 @@ glusterd_update_fs_label (glusterd_brickinfo_t *brickinfo)
/* Ext2/Ext3/Ext4 label is of size 16. Therefore we should
* truncate the label to 16 bytes*/
label [16] = '\0';
- snprintf (msg, sizeof (msg), "Changing filesystem label of "
- "%s brick to %s", brickinfo->path, label);
+ len = snprintf (msg, sizeof (msg), "Changing filesystem label "
+ "of %s brick to %s", brickinfo->path, label);
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
/* For ext2/ext3/ext4 run tune2fs to change the
* file-system label */
runner_add_args (&runner, "tune2fs", "-L", label,
@@ -8818,6 +8879,7 @@ glusterd_remove_trashpath (char *volname)
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
struct stat stbuf = {0, };
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -8825,9 +8887,12 @@ glusterd_remove_trashpath (char *volname)
GF_ASSERT (volname);
- snprintf (delete_path, sizeof (delete_path),
- "%s/"GLUSTERD_TRASH"/vols-%s.deleted", priv->workdir,
- volname);
+ len = snprintf (delete_path, sizeof (delete_path),
+ "%s/"GLUSTERD_TRASH"/vols-%s.deleted", priv->workdir,
+ volname);
+ if ((len < 0) || (len >= sizeof(delete_path))) {
+ goto out;
+ }
ret = sys_lstat (delete_path, &stbuf);
if (ret) {
@@ -8927,6 +8992,7 @@ glusterd_snapshot_revert_partial_restored_vol (glusterd_volinfo_t *volinfo)
glusterd_volinfo_t *tmp_vol = NULL;
glusterd_conf_t *priv = NULL;
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -8936,9 +9002,13 @@ glusterd_snapshot_revert_partial_restored_vol (glusterd_volinfo_t *volinfo)
GLUSTERD_GET_VOLUME_DIR (pathname, volinfo, priv);
- snprintf (trash_path, sizeof (trash_path),
- "%s/"GLUSTERD_TRASH"/vols-%s.deleted", priv->workdir,
- volinfo->volname);
+ len = snprintf (trash_path, sizeof (trash_path),
+ "%s/"GLUSTERD_TRASH"/vols-%s.deleted", priv->workdir,
+ volinfo->volname);
+ if ((len < 0) || (len >= sizeof(trash_path))) {
+ ret = -1;
+ goto out;
+ }
/* Since snapshot restore failed we cannot rely on the volume
* data stored under vols folder. Therefore delete the origin
diff --git a/xlators/mgmt/glusterd/src/glusterd-statedump.c b/xlators/mgmt/glusterd/src/glusterd-statedump.c
index d0a97053485..02b6ddc9662 100644
--- a/xlators/mgmt/glusterd/src/glusterd-statedump.c
+++ b/xlators/mgmt/glusterd/src/glusterd-statedump.c
@@ -20,10 +20,10 @@ static void
glusterd_dump_peer (glusterd_peerinfo_t *peerinfo, char *input_key, int index,
gf_boolean_t xpeers)
{
- char subkey[50] = {0,};
- char key[GF_DUMP_MAX_BUF_LEN] = {0,};
+ char subkey[144] = {0,};
+ char key[128] = {0,};
- strncpy (key, input_key, (GF_DUMP_MAX_BUF_LEN - 1));
+ strncpy (key, input_key, sizeof(key) - 1);
snprintf (subkey, sizeof (subkey), "%s%d", key, index);
@@ -64,10 +64,10 @@ glusterd_dump_peer_rpcstat (glusterd_peerinfo_t *peerinfo, char *input_key,
int ret = -1;
rpc_clnt_t *rpc = NULL;
char rpcsvc_peername[RPCSVC_PEER_STRLEN] = {0,};
- char subkey[50] = {0,};
- char key[GF_DUMP_MAX_BUF_LEN] = {0,};
+ char subkey[144] = {0,};
+ char key[128] = {0,};
- strncpy (key, input_key, (GF_DUMP_MAX_BUF_LEN - 1));
+ strncpy (key, input_key, sizeof(key) - 1);
/* Dump the rpc connection statistics */
rpc = peerinfo->rpc;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index b6efac5a51a..c42c5ea613e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -291,7 +291,7 @@ gd_store_brick_snap_details_write (int fd, glusterd_brickinfo_t *brickinfo)
int ret = -1;
xlator_t *this = NULL;
glusterd_conf_t *conf = NULL;
- char value[256] = {0,};
+ char value[PATH_MAX] = {0,};
this = THIS;
GF_ASSERT (this != NULL);
@@ -640,6 +640,7 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo, char *delete_path)
struct dirent scratch[2] = {{0,},};
char path[PATH_MAX] = {0,};
char brickdir[PATH_MAX] = {0,};
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -655,20 +656,26 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo, char *delete_path)
priv = this->private;
GF_ASSERT (priv);
- snprintf (brickdir, sizeof (brickdir), "%s/%s", delete_path,
- GLUSTERD_BRICK_INFO_DIR);
+ len = snprintf (brickdir, sizeof (brickdir), "%s/%s", delete_path,
+ GLUSTERD_BRICK_INFO_DIR);
+ if ((len < 0) || (len >= sizeof(brickdir))) {
+ ret = -1;
+ goto out;
+ }
dir = sys_opendir (brickdir);
GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch);
while (entry) {
- snprintf (path, sizeof (path), "%s/%s",
- brickdir, entry->d_name);
- ret = sys_unlink (path);
- if (ret && errno != ENOENT) {
- gf_msg_debug (this->name, 0, "Unable to unlink %s",
- path);
+ len = snprintf (path, sizeof (path), "%s/%s",
+ brickdir, entry->d_name);
+ if ((len >= 0) && (len < sizeof(path))) {
+ ret = sys_unlink (path);
+ if (ret && errno != ENOENT) {
+ gf_msg_debug (this->name, 0,
+ "Unable to unlink %s", path);
+ }
}
GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch);
}
@@ -1846,6 +1853,7 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
char trashdir[PATH_MAX] = {0,};
xlator_t *this = NULL;
gf_boolean_t rename_fail = _gf_false;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -1857,12 +1865,20 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
GLUSTERD_GET_VOLUME_DIR (pathname, volinfo, priv);
- snprintf (delete_path, sizeof (delete_path),
- "%s/"GLUSTERD_TRASH"/%s.deleted", priv->workdir,
- uuid_utoa (volinfo->volume_id));
+ len = snprintf (delete_path, sizeof (delete_path),
+ "%s/"GLUSTERD_TRASH"/%s.deleted", priv->workdir,
+ uuid_utoa (volinfo->volume_id));
+ if ((len < 0) || (len >= sizeof(delete_path))) {
+ ret = -1;
+ goto out;
+ }
- snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH,
- priv->workdir);
+ len = snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH,
+ priv->workdir);
+ if ((len < 0) || (len >= sizeof(trashdir))) {
+ ret = -1;
+ goto out;
+ }
ret = sys_mkdir (trashdir, 0777);
if (ret && errno != EEXIST) {
@@ -1916,6 +1932,7 @@ glusterd_store_delete_snap (glusterd_snap_t *snap)
struct stat st = {0, };
xlator_t *this = NULL;
gf_boolean_t rename_fail = _gf_false;
+ int32_t len = 0;
this = THIS;
priv = this->private;
@@ -1924,12 +1941,20 @@ glusterd_store_delete_snap (glusterd_snap_t *snap)
GF_ASSERT (snap);
GLUSTERD_GET_SNAP_DIR (pathname, snap, priv);
- snprintf (delete_path, sizeof (delete_path),
- "%s/"GLUSTERD_TRASH"/snap-%s.deleted", priv->workdir,
- uuid_utoa (snap->snap_id));
+ len = snprintf (delete_path, sizeof (delete_path),
+ "%s/"GLUSTERD_TRASH"/snap-%s.deleted", priv->workdir,
+ uuid_utoa (snap->snap_id));
+ if ((len < 0) || (len >= sizeof(delete_path))) {
+ ret = -1;
+ goto out;
+ }
- snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH,
- priv->workdir);
+ len = snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH,
+ priv->workdir);
+ if ((len < 0) || (len >= sizeof(trashdir))) {
+ ret = -1;
+ goto out;
+ }
ret = sys_mkdir (trashdir, 0777);
if (ret && errno != EEXIST) {
@@ -1959,7 +1984,12 @@ glusterd_store_delete_snap (glusterd_snap_t *snap)
GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch);
while (entry) {
- snprintf (path, PATH_MAX, "%s/%s", delete_path, entry->d_name);
+ len = snprintf (path, PATH_MAX, "%s/%s", delete_path,
+ entry->d_name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto stat_failed;
+ }
ret = sys_stat (path, &st);
if (ret == -1) {
gf_msg_debug (this->name, 0, "Failed to stat "
@@ -2022,6 +2052,7 @@ glusterd_store_global_info (xlator_t *this)
char path[PATH_MAX] = {0,};
gf_store_handle_t *handle = NULL;
char *uuid_str = NULL;
+ int32_t len = 0;
conf = this->private;
@@ -2030,8 +2061,11 @@ glusterd_store_global_info (xlator_t *this)
goto out;
if (!conf->handle) {
- snprintf (path, PATH_MAX, "%s/%s", conf->workdir,
- GLUSTERD_INFO_FILE);
+ len = snprintf (path, PATH_MAX, "%s/%s", conf->workdir,
+ GLUSTERD_INFO_FILE);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
ret = gf_store_handle_new (path, &handle);
if (ret) {
gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -2114,12 +2148,16 @@ glusterd_retrieve_op_version (xlator_t *this, int *op_version)
char *tmp = NULL;
char path[PATH_MAX] = {0,};
gf_store_handle_t *handle = NULL;
+ int32_t len = 0;
priv = this->private;
if (!priv->handle) {
- snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
- GLUSTERD_INFO_FILE);
+ len = snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
+ GLUSTERD_INFO_FILE);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &handle);
if (ret) {
@@ -2167,6 +2205,7 @@ glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit,
char *tmp = NULL;
char path[PATH_MAX] = {0,};
gf_store_handle_t *handle = NULL;
+ int32_t len = 0;
GF_ASSERT (this);
priv = this->private;
@@ -2176,8 +2215,11 @@ glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit,
GF_ASSERT (key);
if (!priv->handle) {
- snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
- GLUSTERD_INFO_FILE);
+ len = snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
+ GLUSTERD_INFO_FILE);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &handle);
if (ret) {
@@ -2282,13 +2324,17 @@ glusterd_retrieve_uuid ()
glusterd_conf_t *priv = NULL;
xlator_t *this = NULL;
char path[PATH_MAX] = {0,};
+ int32_t len = 0;
this = THIS;
priv = this->private;
if (!priv->handle) {
- snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
- GLUSTERD_INFO_FILE);
+ len = snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
+ GLUSTERD_INFO_FILE);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &handle);
if (ret) {
@@ -2332,6 +2378,7 @@ glusterd_store_retrieve_snapd (glusterd_volinfo_t *volinfo)
glusterd_conf_t *conf = NULL;
gf_store_iter_t *iter = NULL;
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2364,8 +2411,11 @@ glusterd_store_retrieve_snapd (glusterd_volinfo_t *volinfo)
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, conf);
- snprintf (path, sizeof (path), "%s/%s", volpath,
- GLUSTERD_VOLUME_SNAPD_INFO_FILE);
+ len = snprintf (path, sizeof (path), "%s/%s", volpath,
+ GLUSTERD_VOLUME_SNAPD_INFO_FILE);
+ if ((len < 0) || (len >= sizeof(path))) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &volinfo->snapd.handle);
if (ret) {
@@ -2438,6 +2488,7 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
xlator_t *this = NULL;
int brickid = 0;
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
+ int32_t len = 0;
GF_ASSERT (volinfo);
GF_ASSERT (volinfo->volname);
@@ -2460,11 +2511,14 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
snprintf (tmpkey, sizeof (tmpkey), "%s-%d",
GLUSTERD_STORE_KEY_VOL_BRICK,brick_count);
ret = gf_store_iter_get_matching (tmpiter, tmpkey, &tmpvalue);
- snprintf (path, sizeof (path), "%s/%s", brickdir, tmpvalue);
-
+ len = snprintf (path, sizeof (path), "%s/%s", brickdir,
+ tmpvalue);
GF_FREE (tmpvalue);
-
tmpvalue = NULL;
+ if ((len < 0) || (len >= sizeof(path))) {
+ ret = -1;
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &brickinfo->shandle);
@@ -2674,6 +2728,7 @@ glusterd_store_retrieve_node_state (glusterd_volinfo_t *volinfo)
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
dict_t *tmp_dict = NULL;
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2682,8 +2737,11 @@ glusterd_store_retrieve_node_state (glusterd_volinfo_t *volinfo)
GF_ASSERT (volinfo);
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv);
- snprintf (path, sizeof (path), "%s/%s", volpath,
- GLUSTERD_NODE_STATE_FILE);
+ len = snprintf (path, sizeof (path), "%s/%s", volpath,
+ GLUSTERD_NODE_STATE_FILE);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &volinfo->node_state_shandle);
if (ret)
@@ -2846,6 +2904,7 @@ glusterd_store_update_volinfo (glusterd_volinfo_t *volinfo)
glusterd_conf_t *conf = NULL;
gf_store_iter_t *iter = NULL;
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -2854,8 +2913,11 @@ glusterd_store_update_volinfo (glusterd_volinfo_t *volinfo)
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, conf);
- snprintf (path, sizeof (path), "%s/%s", volpath,
- GLUSTERD_VOLUME_INFO_FILE);
+ len = snprintf (path, sizeof (path), "%s/%s", volpath,
+ GLUSTERD_VOLUME_INFO_FILE);
+ if ((len < 0) || (len >= sizeof(path))) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &volinfo->shandle);
if (ret) {
@@ -3332,6 +3394,7 @@ glusterd_store_retrieve_volumes (xlator_t *this, glusterd_snap_t *snap)
glusterd_volinfo_t *volinfo = NULL;
struct stat st = {0,};
char entry_path[PATH_MAX] = {0,};
+ int32_t len = 0;
GF_ASSERT (this);
priv = this->private;
@@ -3339,11 +3402,14 @@ glusterd_store_retrieve_volumes (xlator_t *this, glusterd_snap_t *snap)
GF_ASSERT (priv);
if (snap)
- snprintf (path, PATH_MAX, "%s/snaps/%s", priv->workdir,
- snap->snapname);
+ len = snprintf (path, PATH_MAX, "%s/snaps/%s", priv->workdir,
+ snap->snapname);
else
- snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
- GLUSTERD_VOLUME_DIR_PREFIX);
+ len = snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
+ GLUSTERD_VOLUME_DIR_PREFIX);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
dir = sys_opendir (path);
@@ -3360,7 +3426,12 @@ glusterd_store_retrieve_volumes (xlator_t *this, glusterd_snap_t *snap)
(!strcmp (entry->d_name, "info"))))
goto next;
- snprintf (entry_path, PATH_MAX, "%s/%s", path, entry->d_name);
+ len = snprintf (entry_path, PATH_MAX, "%s/%s", path,
+ entry->d_name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto next;
+ }
ret = sys_lstat (entry_path, &st);
if (ret == -1) {
gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -3678,6 +3749,7 @@ glusterd_store_update_snap (glusterd_snap_t *snap)
glusterd_conf_t *conf = NULL;
gf_store_iter_t *iter = NULL;
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
+ int32_t len = 0;
this = THIS;
conf = this->private;
@@ -3685,8 +3757,11 @@ glusterd_store_update_snap (glusterd_snap_t *snap)
GLUSTERD_GET_SNAP_DIR (snappath, snap, conf);
- snprintf (path, sizeof (path), "%s/%s", snappath,
- GLUSTERD_SNAP_INFO_FILE);
+ len = snprintf (path, sizeof (path), "%s/%s", snappath,
+ GLUSTERD_SNAP_INFO_FILE);
+ if ((len < 0) || (len >= sizeof(path))) {
+ goto out;
+ }
ret = gf_store_handle_retrieve (path, &snap->shandle);
if (ret) {
@@ -3918,13 +3993,18 @@ glusterd_store_retrieve_snaps (xlator_t *this)
DIR *dir = NULL;
struct dirent *entry = NULL;
struct dirent scratch[2] = {{0,},};
+ int32_t len = 0;
GF_ASSERT (this);
priv = this->private;
GF_ASSERT (priv);
- snprintf (path, PATH_MAX, "%s/snaps", priv->workdir);
+ len = snprintf (path, PATH_MAX, "%s/snaps", priv->workdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
dir = sys_opendir (path);
@@ -4093,6 +4173,7 @@ glusterd_store_delete_peerinfo (glusterd_peerinfo_t *peerinfo)
char peerdir[PATH_MAX] = {0,};
char filepath[PATH_MAX] = {0,};
char hostname_path[PATH_MAX] = {0,};
+ int32_t len = 0;
if (!peerinfo) {
@@ -4103,24 +4184,34 @@ glusterd_store_delete_peerinfo (glusterd_peerinfo_t *peerinfo)
this = THIS;
priv = this->private;
- snprintf (peerdir, PATH_MAX, "%s/peers", priv->workdir);
-
+ len = snprintf (peerdir, PATH_MAX, "%s/peers", priv->workdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
if (gf_uuid_is_null (peerinfo->uuid)) {
if (peerinfo->hostname) {
- snprintf (filepath, PATH_MAX, "%s/%s", peerdir,
- peerinfo->hostname);
+ len = snprintf (filepath, PATH_MAX, "%s/%s", peerdir,
+ peerinfo->hostname);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
} else {
ret = 0;
goto out;
}
} else {
-
- snprintf (filepath, PATH_MAX, "%s/%s", peerdir,
- uuid_utoa (peerinfo->uuid));
- snprintf (hostname_path, PATH_MAX, "%s/%s",
- peerdir, peerinfo->hostname);
+ len = snprintf (filepath, PATH_MAX, "%s/%s", peerdir,
+ uuid_utoa (peerinfo->uuid));
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
+ len = snprintf (hostname_path, PATH_MAX, "%s/%s",
+ peerdir, peerinfo->hostname);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto out;
+ }
ret = sys_unlink (hostname_path);
@@ -4362,14 +4453,19 @@ glusterd_store_retrieve_peers (xlator_t *this)
glusterd_peer_hostname_t *address = NULL;
uuid_t tmp_uuid;
gf_boolean_t is_ok;
+ int32_t len;
GF_ASSERT (this);
priv = this->private;
GF_ASSERT (priv);
- snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
- GLUSTERD_PEER_DIR_PREFIX);
+ len = snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
+ GLUSTERD_PEER_DIR_PREFIX);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
dir = sys_opendir (path);
@@ -4392,7 +4488,11 @@ glusterd_store_retrieve_peers (xlator_t *this)
continue;
}
is_ok = _gf_false;
- snprintf (filepath, PATH_MAX, "%s/%s", path, entry->d_name);
+ len = snprintf (filepath, PATH_MAX, "%s/%s", path,
+ entry->d_name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ goto next;
+ }
ret = gf_store_handle_retrieve (filepath, &shandle);
if (ret)
goto next;
@@ -4751,6 +4851,7 @@ glusterd_store_retrieve_quota_version (glusterd_volinfo_t *volinfo)
xlator_t *this = NULL;
glusterd_conf_t *conf = NULL;
gf_store_handle_t *handle = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -4758,8 +4859,11 @@ glusterd_store_retrieve_quota_version (glusterd_volinfo_t *volinfo)
GF_ASSERT (conf);
GLUSTERD_GET_VOLUME_DIR (path, volinfo, conf);
- snprintf (cksum_path, sizeof (cksum_path), "%s/%s", path,
- GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ len = snprintf (cksum_path, sizeof (cksum_path), "%s/%s", path,
+ GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ if ((len < 0) || (len >= sizeof(cksum_path))) {
+ goto out;
+ }
ret = gf_store_handle_new (cksum_path, &handle);
if (ret) {
@@ -4803,13 +4907,17 @@ glusterd_store_save_quota_version_and_cksum (glusterd_volinfo_t *volinfo)
char buf[256] = {0};
int fd = -1;
int32_t ret = -1;
+ int32_t len = 0;
this = THIS;
conf = this->private;
GLUSTERD_GET_VOLUME_DIR (path, volinfo, conf);
- snprintf (cksum_path, sizeof (cksum_path), "%s/%s", path,
- GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ len = snprintf (cksum_path, sizeof (cksum_path), "%s/%s", path,
+ GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ if ((len < 0) || (len >= sizeof(cksum_path))) {
+ goto out;
+ }
ret = gf_store_handle_new (cksum_path, &shandle);
if (ret)
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
index ebb288c7191..fcf8e666d3e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
@@ -153,6 +153,7 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline)
char *localtime_logging = NULL;
char *log_level = NULL;
char daemon_log_level[30] = {0};
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -176,8 +177,13 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline)
runinit (&runner);
if (this->ctx->cmd_args.valgrind) {
- snprintf (valgrind_logfile, PATH_MAX, "%s/valgrind-%s.log",
- svc->proc.logfile, svc->name);
+ len = snprintf (valgrind_logfile, PATH_MAX,
+ "%s/valgrind-%s.log", svc->proc.logfile,
+ svc->name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
runner_add_args (&runner, "valgrind", "--leak-check=full",
"--trace-children=yes", "--track-origins=yes",
diff --git a/xlators/mgmt/glusterd/src/glusterd-tier.c b/xlators/mgmt/glusterd/src/glusterd-tier.c
index 264e36295a8..446cb33ff11 100644
--- a/xlators/mgmt/glusterd/src/glusterd-tier.c
+++ b/xlators/mgmt/glusterd/src/glusterd-tier.c
@@ -1113,7 +1113,7 @@ glusterd_add_tierd_to_dict (glusterd_volinfo_t *volinfo,
int32_t pid = -1;
int32_t brick_online = -1;
char key[1024] = {0};
- char base_key[1024] = {0};
+ char base_key[32] = {0};
char pidfile[PATH_MAX] = {0};
xlator_t *this = NULL;
diff --git a/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c
index b555a1a9ccb..42cf8968429 100644
--- a/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c
+++ b/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c
@@ -34,10 +34,14 @@ glusterd_svc_build_tierd_socket_filepath (glusterd_volinfo_t *volinfo,
{
char sockfilepath[PATH_MAX] = {0,};
char rundir[PATH_MAX] = {0,};
+ int32_t len = 0;
glusterd_svc_build_tierd_rundir (volinfo, rundir, sizeof (rundir));
- snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
- rundir, uuid_utoa (MY_UUID));
+ len = snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
+ rundir, uuid_utoa (MY_UUID));
+ if ((len < 0) || (len >= sizeof(sockfilepath))) {
+ sockfilepath[0] = 0;
+ }
glusterd_set_socket_filepath (sockfilepath, path, path_len);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c b/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c
index 9adb8462cdb..9ea6f16a74c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c
+++ b/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c
@@ -53,6 +53,7 @@ glusterd_tierdsvc_init (void *data)
glusterd_conn_notify_t notify = NULL;
xlator_t *this = NULL;
char *volfileserver = NULL;
+ int32_t len = 0;
this = THIS;
GF_VALIDATE_OR_GOTO (THIS->name, this, out);
@@ -98,7 +99,12 @@ glusterd_tierdsvc_init (void *data)
goto out;
}
glusterd_svc_build_tierd_logfile (logfile, logdir, sizeof (logfile));
- snprintf (volfileid, sizeof (volfileid), "tierd/%s", volinfo->volname);
+ len = snprintf (volfileid, sizeof (volfileid), "tierd/%s",
+ volinfo->volname);
+ if ((len < 0) || (len >= sizeof(volfileid))) {
+ ret = -1;
+ goto out;
+ }
if (dict_get_str (this->options, "transport.socket.bind-address",
&volfileserver) != 0) {
@@ -260,6 +266,7 @@ glusterd_tierdsvc_start (glusterd_svc_t *svc, int flags)
glusterd_tierdsvc_t *tierd = NULL;
int cmd = GF_DEFRAG_CMD_START_TIER;
char *localtime_logging = NULL;
+ int32_t len = 0;
this = THIS;
GF_VALIDATE_OR_GOTO (THIS->name, this, out);
@@ -315,8 +322,12 @@ glusterd_tierdsvc_start (glusterd_svc_t *svc, int flags)
runinit (&runner);
if (this->ctx->cmd_args.valgrind) {
- snprintf (valgrind_logfile, PATH_MAX, "%s/valgrind-tierd.log",
- svc->proc.logdir);
+ len = snprintf (valgrind_logfile, PATH_MAX,
+ "%s/valgrind-tierd.log", svc->proc.logdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
runner_add_args (&runner, "valgrind", "--leak-check=full",
"--trace-children=yes", "--track-origins=yes",
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 7d039a23f1a..385df1ea01b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1449,14 +1449,15 @@ glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
char msg[2048] = {0,};
gf_boolean_t is_created = _gf_false;
char glusterfs_dir_path[PATH_MAX] = {0};
+ int32_t len = 0;
ret = sys_mkdir (brickinfo->path, 0777);
if (ret) {
if (errno != EEXIST) {
- snprintf (msg, sizeof (msg), "Failed to create brick "
- "directory for brick %s:%s. Reason : %s ",
- brickinfo->hostname, brickinfo->path,
- strerror (errno));
+ len = snprintf (msg, sizeof (msg), "Failed to create "
+ "brick directory for brick %s:%s. "
+ "Reason : %s ", brickinfo->hostname,
+ brickinfo->path, strerror (errno));
goto out;
}
} else {
@@ -1465,60 +1466,70 @@ glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
ret = sys_lstat (brickinfo->path, &brick_st);
if (ret) {
- snprintf (msg, sizeof (msg), "lstat failed on %s. Reason : %s",
- brickinfo->path, strerror (errno));
+ len = snprintf (msg, sizeof (msg), "lstat failed on %s. "
+ "Reason : %s", brickinfo->path,
+ strerror (errno));
goto out;
}
if ((!is_created) && (!S_ISDIR (brick_st.st_mode))) {
- snprintf (msg, sizeof (msg), "The provided path %s which is "
- "already present, is not a directory",
- brickinfo->path);
+ len = snprintf (msg, sizeof (msg), "The provided path %s "
+ "which is already present, is not a directory",
+ brickinfo->path);
ret = -1;
goto out;
}
- snprintf (parentdir, sizeof (parentdir), "%s/..", brickinfo->path);
+ len = snprintf (parentdir, sizeof (parentdir), "%s/..",
+ brickinfo->path);
+ if ((len < 0) || (len >= sizeof(parentdir))) {
+ ret = -1;
+ goto out;
+ }
ret = sys_lstat ("/", &root_st);
if (ret) {
- snprintf (msg, sizeof (msg), "lstat failed on /. Reason : %s",
- strerror (errno));
+ len = snprintf (msg, sizeof (msg), "lstat failed on /. "
+ "Reason : %s", strerror (errno));
goto out;
}
ret = sys_lstat (parentdir, &parent_st);
if (ret) {
- snprintf (msg, sizeof (msg), "lstat failed on %s. Reason : %s",
- parentdir, strerror (errno));
+ len = snprintf (msg, sizeof (msg), "lstat failed on %s. "
+ "Reason : %s", parentdir, strerror (errno));
goto out;
}
if (!is_force) {
if (brick_st.st_dev != parent_st.st_dev) {
- snprintf (msg, sizeof (msg), "The brick %s:%s is a "
- "mount point. Please create a sub-directory "
- "under the mount point and use that as the "
- "brick directory. Or use 'force' at the end "
- "of the command if you want to override this "
- "behavior.", brickinfo->hostname,
- brickinfo->path);
+ len = snprintf (msg, sizeof (msg), "The brick %s:%s "
+ "is a mount point. Please create a "
+ "sub-directory under the mount point "
+ "and use that as the brick directory. "
+ "Or use 'force' at the end of the "
+ "command if you want to override this "
+ "behavior.", brickinfo->hostname,
+ brickinfo->path);
ret = -1;
goto out;
}
else if (parent_st.st_dev == root_st.st_dev) {
- snprintf (msg, sizeof (msg), "The brick %s:%s "
- "is being created in the root partition. It "
- "is recommended that you don't use the "
- "system's root partition for storage backend."
- " Or use 'force' at the end of the command if"
- " you want to override this behavior.",
- brickinfo->hostname, brickinfo->path);
+ len = snprintf (msg, sizeof (msg), "The brick %s:%s "
+ "is being created in the root "
+ "partition. It is recommended that "
+ "you don't use the system's root "
+ "partition for storage backend. Or "
+ "use 'force' at the end of the "
+ "command if you want to override this "
+ "behavior.", brickinfo->hostname,
+ brickinfo->path);
/* If --wignore-partition flag is used, ignore warnings
* related to bricks being on root partition when 'force'
* is not used */
- if (!ignore_partition) {
+ if ((len < 0) || (len >= sizeof(msg)) ||
+ !ignore_partition) {
ret = -1;
goto out;
}
@@ -1540,20 +1551,28 @@ glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
goto out;
/* create .glusterfs directory */
- snprintf (glusterfs_dir_path, sizeof (glusterfs_dir_path), "%s/%s",
- brickinfo->path, ".glusterfs");
+ len = snprintf (glusterfs_dir_path, sizeof (glusterfs_dir_path),
+ "%s/%s", brickinfo->path, ".glusterfs");
+ if ((len < 0) || (len >= sizeof(glusterfs_dir_path))) {
+ ret = -1;
+ goto out;
+ }
+
ret = sys_mkdir (glusterfs_dir_path, 0600);
if (ret && (errno != EEXIST)) {
- snprintf (msg, sizeof (msg), "Failed to create .glusterfs "
- "directory for brick %s:%s. Reason : %s ",
- brickinfo->hostname, brickinfo->path,
- strerror (errno));
+ len = snprintf (msg, sizeof (msg), "Failed to create "
+ ".glusterfs directory for brick %s:%s. "
+ "Reason : %s ", brickinfo->hostname,
+ brickinfo->path, strerror (errno));
goto out;
}
ret = 0;
out:
+ if (len < 0) {
+ ret = -1;
+ }
if (ret && is_created) {
(void)recursive_rmdir (brickinfo->path);
}
@@ -1859,6 +1878,7 @@ glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo,
int expected_file_len = 0;
char export_path[PATH_MAX] = {0,};
char sock_filepath[PATH_MAX] = {0,};
+ int32_t slen = 0;
expected_file_len = strlen (GLUSTERD_SOCK_DIR) + strlen ("/") +
SHA256_DIGEST_LENGTH*2 + strlen (".socket") + 1;
@@ -1870,8 +1890,11 @@ glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo,
GLUSTERD_GET_VOLUME_PID_DIR (volume_dir, volinfo, priv);
GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, export_path);
- snprintf (sock_filepath, PATH_MAX, "%s/run/%s-%s",
- volume_dir, brickinfo->hostname, export_path);
+ slen = snprintf (sock_filepath, PATH_MAX, "%s/run/%s-%s",
+ volume_dir, brickinfo->hostname, export_path);
+ if (slen < 0) {
+ sock_filepath[0] = 0;
+ }
glusterd_set_socket_filepath (sock_filepath, sockpath, len);
}
@@ -1966,6 +1989,7 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
struct rpc_clnt *rpc = NULL;
rpc_clnt_connection_t *conn = NULL;
int pid = -1;
+ int32_t len = 0;
GF_ASSERT (volinfo);
GF_ASSERT (brickinfo);
@@ -2038,15 +2062,19 @@ retry:
if (this->ctx->cmd_args.valgrind) {
/* Run bricks with valgrind */
if (volinfo->logdir) {
- snprintf (valgrind_logfile, PATH_MAX,
- "%s/valgrind-%s-%s.log",
- volinfo->logdir,
- volinfo->volname, exp_path);
+ len = snprintf (valgrind_logfile, PATH_MAX,
+ "%s/valgrind-%s-%s.log",
+ volinfo->logdir,
+ volinfo->volname, exp_path);
} else {
- snprintf (valgrind_logfile, PATH_MAX,
- "%s/bricks/valgrind-%s-%s.log",
- DEFAULT_LOG_FILE_DIRECTORY,
- volinfo->volname, exp_path);
+ len = snprintf (valgrind_logfile, PATH_MAX,
+ "%s/bricks/valgrind-%s-%s.log",
+ DEFAULT_LOG_FILE_DIRECTORY,
+ volinfo->volname, exp_path);
+ }
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
}
runner_add_args (&runner, "valgrind", "--leak-check=full",
@@ -2056,22 +2084,32 @@ retry:
}
if (volinfo->is_snap_volume) {
- snprintf (volfile, PATH_MAX,"/%s/%s/%s.%s.%s",
- GLUSTERD_VOL_SNAP_DIR_PREFIX,
- volinfo->snapshot->snapname, volinfo->volname,
- brickinfo->hostname, exp_path);
+ len = snprintf (volfile, PATH_MAX, "/%s/%s/%s.%s.%s",
+ GLUSTERD_VOL_SNAP_DIR_PREFIX,
+ volinfo->snapshot->snapname, volinfo->volname,
+ brickinfo->hostname, exp_path);
} else {
- snprintf (volfile, PATH_MAX, "%s.%s.%s", volinfo->volname,
- brickinfo->hostname, exp_path);
+ len = snprintf (volfile, PATH_MAX, "%s.%s.%s",
+ volinfo->volname, brickinfo->hostname,
+ exp_path);
+ }
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
}
if (volinfo->logdir) {
- snprintf (logfile, PATH_MAX, "%s/%s.log",
- volinfo->logdir, exp_path);
+ len = snprintf (logfile, PATH_MAX, "%s/%s.log",
+ volinfo->logdir, exp_path);
} else {
- snprintf (logfile, PATH_MAX, "%s/bricks/%s.log",
- DEFAULT_LOG_FILE_DIRECTORY, exp_path);
+ len = snprintf (logfile, PATH_MAX, "%s/bricks/%s.log",
+ DEFAULT_LOG_FILE_DIRECTORY, exp_path);
+ }
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
}
+
if (!brickinfo->logfile)
brickinfo->logfile = gf_strdup (logfile);
@@ -2096,8 +2134,12 @@ retry:
if (volinfo->transport_type != GF_TRANSPORT_BOTH_TCP_RDMA) {
runner_argprintf (&runner, "%d", port);
} else {
- snprintf (rdma_brick_path, sizeof(rdma_brick_path), "%s.rdma",
- brickinfo->path);
+ len = snprintf (rdma_brick_path, sizeof(rdma_brick_path),
+ "%s.rdma", brickinfo->path);
+ if ((len < 0) || (len >= sizeof(rdma_brick_path))) {
+ ret = -1;
+ goto out;
+ }
rdma_port = pmap_assign_port (THIS, brickinfo->rdma_port,
rdma_brick_path);
if (!rdma_port) {
@@ -2752,6 +2794,8 @@ int glusterd_compute_cksum (glusterd_volinfo_t *volinfo,
char filepath[PATH_MAX] = {0,};
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
+ int32_t len1 = 0;
+ int32_t len2 = 0;
this = THIS;
GF_ASSERT (this);
@@ -2761,15 +2805,19 @@ int glusterd_compute_cksum (glusterd_volinfo_t *volinfo,
GLUSTERD_GET_VOLUME_DIR (path, volinfo, conf);
if (is_quota_conf) {
- snprintf (cksum_path, sizeof (cksum_path), "%s/%s", path,
- GLUSTERD_VOL_QUOTA_CKSUM_FILE);
- snprintf (filepath, sizeof (filepath), "%s/%s", path,
- GLUSTERD_VOLUME_QUOTA_CONFIG);
+ len1 = snprintf (cksum_path, sizeof (cksum_path), "%s/%s",
+ path, GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ len2 = snprintf (filepath, sizeof (filepath), "%s/%s", path,
+ GLUSTERD_VOLUME_QUOTA_CONFIG);
} else {
- snprintf (cksum_path, sizeof (cksum_path), "%s/%s", path,
- GLUSTERD_CKSUM_FILE);
- snprintf (filepath, sizeof (filepath), "%s/%s", path,
- GLUSTERD_VOLUME_INFO_FILE);
+ len1 = snprintf (cksum_path, sizeof (cksum_path), "%s/%s",
+ path, GLUSTERD_CKSUM_FILE);
+ len2 = snprintf (filepath, sizeof (filepath), "%s/%s", path,
+ GLUSTERD_VOLUME_INFO_FILE);
+ }
+ if ((len1 < 0) || (len2 < 0) ||
+ (len1 >= sizeof(cksum_path)) || (len2 >= sizeof(filepath))) {
+ goto out;
}
ret = glusterd_volume_compute_cksum (volinfo, cksum_path, filepath,
@@ -5568,6 +5616,7 @@ attach_brick (xlator_t *this,
int ret = -1;
int tries;
rpc_clnt_t *rpc;
+ int32_t len;
gf_log (this->name, GF_LOG_INFO,
"add brick %s to existing process for %s",
@@ -5579,14 +5628,20 @@ attach_brick (xlator_t *this,
GLUSTERD_GET_BRICK_PIDFILE (pidfile2, volinfo, brickinfo, conf);
if (volinfo->is_snap_volume) {
- snprintf (full_id, sizeof(full_id), "/%s/%s/%s.%s.%s",
- GLUSTERD_VOL_SNAP_DIR_PREFIX,
- volinfo->snapshot->snapname,
- volinfo->volname, brickinfo->hostname, unslashed);
+ len = snprintf (full_id, sizeof(full_id), "/%s/%s/%s.%s.%s",
+ GLUSTERD_VOL_SNAP_DIR_PREFIX,
+ volinfo->snapshot->snapname,
+ volinfo->volname, brickinfo->hostname,
+ unslashed);
} else {
- snprintf (full_id, sizeof(full_id), "%s.%s.%s",
- volinfo->volname, brickinfo->hostname, unslashed);
+ len = snprintf (full_id, sizeof(full_id), "%s.%s.%s",
+ volinfo->volname, brickinfo->hostname,
+ unslashed);
}
+ if ((len < 0) || (len >= sizeof(full_id))) {
+ goto out;
+ }
+
(void) build_volfile_path (full_id, path, sizeof(path), NULL);
@@ -5646,6 +5701,7 @@ attach_brick (xlator_t *this,
synclock_lock (&conf->big_lock);
}
+out:
gf_log (this->name, GF_LOG_WARNING,
"attach failed for %s", brickinfo->path);
return ret;
@@ -6876,7 +6932,7 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
int ret = -1;
char key[1024] = {0};
char buff [PATH_MAX] = {0};
- char base_key[1024] = {0};
+ char base_key[32] = {0};
struct mntent save_entry = {0};
char *mnt_pt = NULL;
struct mntent *entry = NULL;
@@ -6978,7 +7034,7 @@ glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
uint64_t inodes_total = 0;
uint64_t inodes_free = 0;
uint64_t block_size = 0;
- char key[1024] = {0};
+ char key[1024 + 16] = {0};
char base_key[1024] = {0};
struct statvfs brickstat = {0};
xlator_t *this = NULL;
@@ -7061,7 +7117,7 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo,
int ret = -1;
int32_t pid = -1;
- char key[1024] = {0};
+ char key[1024 + 16] = {0};
char base_key[1024] = {0};
char pidfile[PATH_MAX] = {0};
xlator_t *this = NULL;
@@ -8653,13 +8709,17 @@ glusterd_get_bitd_filepath (char *filepath, glusterd_volinfo_t *volinfo)
int ret = 0;
char path[PATH_MAX] = {0,};
glusterd_conf_t *priv = NULL;
+ int32_t len = 0;
priv = THIS->private;
GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv);
- snprintf (filepath, PATH_MAX,
- "%s/%s-bitd.vol", path, volinfo->volname);
+ len = snprintf (filepath, PATH_MAX,
+ "%s/%s-bitd.vol", path, volinfo->volname);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ }
return ret;
}
@@ -8671,6 +8731,7 @@ glusterd_get_client_filepath (char *filepath, glusterd_volinfo_t *volinfo,
int ret = 0;
char path[PATH_MAX] = {0,};
glusterd_conf_t *priv = NULL;
+ int32_t len = 0;
priv = THIS->private;
@@ -8678,18 +8739,21 @@ glusterd_get_client_filepath (char *filepath, glusterd_volinfo_t *volinfo,
switch (type) {
case GF_TRANSPORT_TCP:
- snprintf (filepath, PATH_MAX,
- "%s/%s.tcp-fuse.vol", path, volinfo->volname);
+ len = snprintf (filepath, PATH_MAX,
+ "%s/%s.tcp-fuse.vol", path, volinfo->volname);
break;
case GF_TRANSPORT_RDMA:
- snprintf (filepath, PATH_MAX,
- "%s/%s.rdma-fuse.vol", path, volinfo->volname);
+ len = snprintf (filepath, PATH_MAX,
+ "%s/%s.rdma-fuse.vol", path, volinfo->volname);
break;
default:
ret = -1;
break;
}
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ }
return ret;
}
@@ -8702,6 +8766,7 @@ glusterd_get_trusted_client_filepath (char *filepath,
int ret = 0;
char path[PATH_MAX] = {0,};
glusterd_conf_t *priv = NULL;
+ int32_t len = 0;
priv = THIS->private;
@@ -8709,18 +8774,23 @@ glusterd_get_trusted_client_filepath (char *filepath,
switch (type) {
case GF_TRANSPORT_TCP:
- snprintf (filepath, PATH_MAX, "%s/trusted-%s.tcp-fuse.vol",
- path, volinfo->volname);
+ len = snprintf (filepath, PATH_MAX,
+ "%s/trusted-%s.tcp-fuse.vol", path,
+ volinfo->volname);
break;
case GF_TRANSPORT_RDMA:
- snprintf (filepath, PATH_MAX, "%s/trusted-%s.rdma-fuse.vol",
- path, volinfo->volname);
+ len = snprintf (filepath, PATH_MAX,
+ "%s/trusted-%s.rdma-fuse.vol", path,
+ volinfo->volname);
break;
default:
ret = -1;
break;
}
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ }
return ret;
}
@@ -9686,7 +9756,7 @@ static int
_profile_volume_add_friend_rsp (dict_t *this, char *key, data_t *value,
void *data)
{
- char new_key[256] = {0};
+ char new_key[264] = {0};
glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL;
data_t *new_value = NULL;
int brick_count = 0;
@@ -9753,7 +9823,8 @@ glusterd_volume_status_add_peer_rsp (dict_t *this, char *key, data_t *value,
char brick_key[1024] = {0,};
char new_key[1024] = {0,};
int32_t index = 0;
- int32_t ret = 0;
+ int32_t ret = -1;
+ int32_t len = 0;
/* Skip the following keys, they are already present in the ctx_dict */
/* Also, skip all the task related pairs. They will be added to the
@@ -9771,19 +9842,25 @@ glusterd_volume_status_add_peer_rsp (dict_t *this, char *key, data_t *value,
sscanf (key, "brick%d.%s", &index, brick_key);
if (index > rsp_ctx->brick_index_max) {
- snprintf (new_key, sizeof (new_key), "brick%d.%s",
- index + rsp_ctx->other_count, brick_key);
+ len = snprintf (new_key, sizeof (new_key), "brick%d.%s",
+ index + rsp_ctx->other_count, brick_key);
+ if ((len < 0) || (len >= sizeof(new_key))) {
+ goto out;
+ }
} else {
strncpy (new_key, key, sizeof (new_key));
new_key[sizeof (new_key) - 1] = 0;
}
ret = dict_set (rsp_ctx->dict, new_key, new_value);
- if (ret)
+out:
+ if (ret) {
+ data_unref(new_value);
gf_msg ("glusterd", GF_LOG_ERROR, 0,
GD_MSG_DICT_SET_FAILED,
"Unable to set key: %s in dict",
key);
+ }
return 0;
}
@@ -12538,6 +12615,7 @@ glusterd_clean_up_quota_store (glusterd_volinfo_t *volinfo)
char cksum_path[PATH_MAX] = {0,};
xlator_t *this = NULL;
glusterd_conf_t *conf = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -12546,10 +12624,16 @@ glusterd_clean_up_quota_store (glusterd_volinfo_t *volinfo)
GLUSTERD_GET_VOLUME_DIR (voldir, volinfo, conf);
- snprintf (quota_confpath, sizeof (quota_confpath), "%s/%s", voldir,
- GLUSTERD_VOLUME_QUOTA_CONFIG);
- snprintf (cksum_path, sizeof (cksum_path), "%s/%s", voldir,
- GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ len = snprintf (quota_confpath, sizeof (quota_confpath), "%s/%s",
+ voldir, GLUSTERD_VOLUME_QUOTA_CONFIG);
+ if ((len < 0) || (len >= sizeof(quota_confpath))) {
+ quota_confpath[0] = 0;
+ }
+ len = snprintf (cksum_path, sizeof (cksum_path), "%s/%s", voldir,
+ GLUSTERD_VOL_QUOTA_CKSUM_FILE);
+ if ((len < 0) || (len >= sizeof(cksum_path))) {
+ cksum_path[0] = 0;
+ }
sys_unlink (quota_confpath);
sys_unlink (cksum_path);
@@ -13375,7 +13459,7 @@ cont:
"Libxml not present");
#endif
- if (xml_out)
+ if (xml_out) {
#if (HAVE_LIB_XML)
output = gf_strdup ((char *)buf->content);
if (NULL == output) {
@@ -13387,6 +13471,7 @@ cont:
GD_MSG_MODULE_NOT_INSTALLED,
"Libxml not present");
#endif
+ }
ret = dict_set_dynstr (ctx, "help-str", output);
if (ret >= 0) {
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index fbb8013931b..76266e1e194 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1830,6 +1830,7 @@ brick_graph_add_changelog (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
xlator_t *xl = NULL;
char changelog_basepath[PATH_MAX] = {0,};
int ret = -1;
+ int32_t len = 0;
if (!graph || !volinfo || !set_dict || !brickinfo)
goto out;
@@ -1842,8 +1843,12 @@ brick_graph_add_changelog (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
if (ret)
goto out;
- snprintf (changelog_basepath, sizeof (changelog_basepath),
- "%s/%s", brickinfo->path, ".glusterfs/changelogs");
+ len = snprintf (changelog_basepath, sizeof (changelog_basepath),
+ "%s/%s", brickinfo->path, ".glusterfs/changelogs");
+ if ((len < 0) || (len >= sizeof(changelog_basepath))) {
+ ret = -1;
+ goto out;
+ }
ret = xlator_set_option (xl, "changelog-dir", changelog_basepath);
if (ret)
goto out;
@@ -2187,6 +2192,7 @@ brick_graph_add_index (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
char *pending_xattr = NULL;
char index_basepath[PATH_MAX] = {0};
int ret = -1;
+ int32_t len = 0;
if (!graph || !volinfo || !brickinfo || !set_dict)
goto out;
@@ -2200,8 +2206,11 @@ brick_graph_add_index (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
if (!xl)
goto out;
- snprintf (index_basepath, sizeof (index_basepath), "%s/%s",
- brickinfo->path, ".glusterfs/indices");
+ len = snprintf (index_basepath, sizeof (index_basepath), "%s/%s",
+ brickinfo->path, ".glusterfs/indices");
+ if ((len < 0) || (len >= sizeof(index_basepath))) {
+ goto out;
+ }
ret = xlator_set_option (xl, "index-base", index_basepath);
if (ret)
@@ -2474,6 +2483,7 @@ brick_graph_add_server (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
char *ssl_user = NULL;
char *volname = NULL;
char *address_family_data = NULL;
+ int32_t len = 0;
if (!graph || !volinfo || !set_dict || !brickinfo)
goto out;
@@ -2523,8 +2533,11 @@ brick_graph_add_server (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
if (username) {
memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "auth.login.%s.allow",
- brickinfo->path);
+ len = snprintf (key, sizeof (key), "auth.login.%s.allow",
+ brickinfo->path);
+ if ((len < 0) || (len >= sizeof(key))) {
+ return -1;
+ }
ret = xlator_set_option (xl, key, username);
if (ret)
@@ -2563,8 +2576,11 @@ brick_graph_add_server (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
if (dict_get_str (volinfo->dict, "auth.ssl-allow", &ssl_user) == 0) {
memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "auth.login.%s.ssl-allow",
- brickinfo->path);
+ len = snprintf (key, sizeof (key), "auth.login.%s.ssl-allow",
+ brickinfo->path);
+ if ((len < 0) || (len >= sizeof(key))) {
+ return -1;
+ }
ret = xlator_set_option (xl, key, ssl_user);
if (ret)
@@ -5638,6 +5654,7 @@ get_brick_filepath (char *filename, glusterd_volinfo_t *volinfo,
char path[PATH_MAX] = {0,};
char brick[PATH_MAX] = {0,};
glusterd_conf_t *priv = NULL;
+ int32_t len = 0;
priv = THIS->private;
@@ -5645,13 +5662,16 @@ get_brick_filepath (char *filename, glusterd_volinfo_t *volinfo,
GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv);
if (prefix)
- snprintf (filename, PATH_MAX, "%s/%s.%s.%s.%s.vol",
- path, volinfo->volname, prefix,
- brickinfo->hostname, brick);
+ len = snprintf (filename, PATH_MAX, "%s/%s.%s.%s.%s.vol",
+ path, volinfo->volname, prefix,
+ brickinfo->hostname, brick);
else
- snprintf (filename, PATH_MAX, "%s/%s.%s.%s.vol",
- path, volinfo->volname,
- brickinfo->hostname, brick);
+ len = snprintf (filename, PATH_MAX, "%s/%s.%s.%s.vol",
+ path, volinfo->volname,
+ brickinfo->hostname, brick);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ filename[0] = 0;
+ }
}
@@ -5877,16 +5897,18 @@ get_parent_vol_tstamp_file (char *filename, glusterd_volinfo_t *volinfo)
{
glusterd_conf_t *priv = NULL;
xlator_t *this = NULL;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
priv = this->private;
GF_ASSERT (priv);
- snprintf (filename, PATH_MAX, "%s/vols/%s", priv->workdir,
- volinfo->parent_volname);
- strncat (filename, "/marker.tstamp",
- PATH_MAX - strlen(filename) - 1);
+ len = snprintf (filename, PATH_MAX, "%s/vols/%s/marker.tstamp",
+ priv->workdir, volinfo->parent_volname);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ filename[0] = 0;
+ }
}
void
@@ -6438,7 +6460,7 @@ build_bitd_volume_graph (volgen_graph_t *graph,
get_transport_type (volinfo, set_dict, transt, _gf_false);
if (!strncmp (transt, "tcp,rdma", strlen ("tcp,rdma")))
- strncpy (transt, "tcp", strlen ("tcp"));
+ strncpy (transt, "tcp", sizeof(transt));
cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
if (!glusterd_is_local_brick (this, volinfo, brickinfo))
@@ -6600,7 +6622,7 @@ build_scrub_volume_graph (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
get_transport_type (volinfo, set_dict, transt, _gf_false);
if (!strncmp (transt, "tcp,rdma", strlen ("tcp,rdma")))
- strncpy (transt, "tcp", strlen ("tcp"));
+ strncpy (transt, "tcp", sizeof(transt));
cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
if (!glusterd_is_local_brick (this, volinfo, brickinfo))
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
index e46ef57e441..3973a0da78a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
@@ -1507,6 +1507,7 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr,
char volid[50] = {0,};
char xattr_volid[50] = {0,};
int caps = 0;
+ int32_t len = 0;
this = THIS;
GF_ASSERT (this);
@@ -1585,19 +1586,25 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr,
if (ret && (flags & GF_CLI_FLAG_OP_FORCE)) {
continue;
} else if (ret) {
- snprintf (msg, sizeof (msg), "Failed to find "
- "brick directory %s for volume %s. "
- "Reason : %s", brickinfo->path,
- volname, strerror (errno));
+ len = snprintf (msg, sizeof (msg), "Failed to find "
+ "brick directory %s for volume %s. "
+ "Reason : %s", brickinfo->path,
+ volname, strerror (errno));
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
goto out;
}
ret = sys_lgetxattr (brickinfo->path, GF_XATTR_VOL_ID_KEY,
volume_id, 16);
if (ret < 0 && (!(flags & GF_CLI_FLAG_OP_FORCE))) {
- snprintf (msg, sizeof (msg), "Failed to get "
- "extended attribute %s for brick dir %s. "
- "Reason : %s", GF_XATTR_VOL_ID_KEY,
- brickinfo->path, strerror (errno));
+ len = snprintf (msg, sizeof (msg), "Failed to get "
+ "extended attribute %s for brick dir "
+ "%s. Reason : %s", GF_XATTR_VOL_ID_KEY,
+ brickinfo->path, strerror (errno));
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
ret = -1;
goto out;
} else if (ret < 0) {
@@ -1606,22 +1613,30 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr,
volinfo->volume_id, 16,
XATTR_CREATE);
if (ret == -1) {
- snprintf (msg, sizeof (msg), "Failed to set "
- "extended attribute %s on %s. Reason: "
- "%s", GF_XATTR_VOL_ID_KEY,
- brickinfo->path, strerror (errno));
+ len = snprintf (msg, sizeof (msg), "Failed to "
+ "set extended attribute %s on "
+ "%s. Reason: %s",
+ GF_XATTR_VOL_ID_KEY,
+ brickinfo->path,
+ strerror (errno));
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
goto out;
} else {
continue;
}
}
if (gf_uuid_compare (volinfo->volume_id, volume_id)) {
- snprintf (msg, sizeof (msg), "Volume id mismatch for "
- "brick %s:%s. Expected volume id %s, "
- "volume id %s found", brickinfo->hostname,
- brickinfo->path,
- uuid_utoa_r (volinfo->volume_id, volid),
- uuid_utoa_r (volume_id, xattr_volid));
+ len = snprintf (msg, sizeof (msg), "Volume id "
+ "mismatch for brick %s:%s. Expected "
+ "volume id %s, volume id %s found",
+ brickinfo->hostname, brickinfo->path,
+ uuid_utoa_r (volinfo->volume_id, volid),
+ uuid_utoa_r (volume_id, xattr_volid));
+ if (len < 0) {
+ strcpy(msg, "<error>");
+ }
ret = -1;
goto out;
}
@@ -3070,6 +3085,7 @@ glusterd_clearlocks_get_local_client_ports (glusterd_volinfo_t *volinfo,
int ret = -1;
int i = 0;
int port = 0;
+ int32_t len = 0;
GF_ASSERT (xl_opts);
if (!xl_opts) {
@@ -3085,11 +3101,15 @@ glusterd_clearlocks_get_local_client_ports (glusterd_volinfo_t *volinfo,
continue;
if (volinfo->transport_type == GF_TRANSPORT_RDMA) {
- snprintf (brickname, sizeof(brickname), "%s.rdma",
- brickinfo->path);
+ len = snprintf (brickname, sizeof(brickname),
+ "%s.rdma", brickinfo->path);
} else
- snprintf (brickname, sizeof(brickname), "%s",
- brickinfo->path);
+ len = snprintf (brickname, sizeof(brickname), "%s",
+ brickinfo->path);
+ if ((len < 0) || (len >= sizeof(brickname))) {
+ ret = -1;
+ goto out;
+ }
port = pmap_registry_search (THIS, brickname,
GF_PMAP_PORT_BRICKSERVER,
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 316cae4243b..7dc45129312 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -569,6 +569,7 @@ glusterd_crt_georep_folders (char *georepdir, glusterd_conf_t *conf)
char *greplg_s = NULL;
struct group *gr = NULL;
int ret = 0;
+ int32_t len = 0;
GF_ASSERT (georepdir);
GF_ASSERT (conf);
@@ -582,7 +583,11 @@ glusterd_crt_georep_folders (char *georepdir, glusterd_conf_t *conf)
goto out;
}
- snprintf (georepdir, PATH_MAX, "%s/"GEOREP, conf->workdir);
+ len = snprintf (georepdir, PATH_MAX, "%s/"GEOREP, conf->workdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
ret = mkdir_p (georepdir, 0777, _gf_true);
if (-1 == ret) {
gf_msg ("glusterd", GF_LOG_CRITICAL, errno,
@@ -1404,6 +1409,7 @@ init (xlator_t *this)
gf_boolean_t upgrade = _gf_false;
gf_boolean_t downgrade = _gf_false;
char *localtime_logging = NULL;
+ int32_t len = 0;
#ifndef GF_DARWIN_HOST_OS
{
@@ -1503,8 +1509,13 @@ init (xlator_t *this)
exit (1);
}
- snprintf (snap_mount_dir, sizeof(snap_mount_dir), "%s%s",
- var_run_dir, GLUSTERD_DEFAULT_SNAPS_BRICK_DIR);
+ len = snprintf (snap_mount_dir, sizeof(snap_mount_dir), "%s%s",
+ var_run_dir, GLUSTERD_DEFAULT_SNAPS_BRICK_DIR);
+ if ((len < 0) || (len >= sizeof(snap_mount_dir))) {
+ gf_msg (this->name, GF_LOG_CRITICAL, 0,
+ GD_MSG_DIR_OP_FAILED, "Snap mount dir too long");
+ exit(1);
+ }
ret = mkdir_p (GLUSTER_SHARED_STORAGE_BRICK_DIR, 0777,
_gf_true);
@@ -1571,7 +1582,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/vols", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/vols", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
@@ -1584,7 +1598,10 @@ init (xlator_t *this)
}
/*keeping individual volume pid file information in /var/run/gluster* */
- snprintf (storedir, PATH_MAX, "%s/vols", rundir);
+ len = snprintf (storedir, sizeof(storedir), "%s/vols", rundir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
@@ -1596,7 +1613,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/snaps", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/snaps", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
@@ -1608,7 +1628,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/peers", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/peers", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
@@ -1620,7 +1643,12 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/bricks", DEFAULT_LOG_FILE_DIRECTORY);
+ len = snprintf (storedir, sizeof(storedir), "%s/bricks",
+ DEFAULT_LOG_FILE_DIRECTORY);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
+
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
@@ -1630,7 +1658,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/nfs", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/nfs", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
@@ -1640,7 +1671,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/bitd", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/bitd", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
@@ -1650,7 +1684,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/scrub", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/scrub", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
@@ -1660,7 +1697,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/glustershd", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/glustershd", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
@@ -1670,7 +1710,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/quotad", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/quotad", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
@@ -1680,7 +1723,10 @@ init (xlator_t *this)
exit (1);
}
- snprintf (storedir, PATH_MAX, "%s/groups", workdir);
+ len = snprintf (storedir, sizeof(storedir), "%s/groups", workdir);
+ if ((len < 0) || (len >= sizeof(storedir))) {
+ exit(1);
+ }
ret = sys_mkdir (storedir, 0777);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg (this->name, GF_LOG_CRITICAL, errno,
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 33413976e6d..fa053e0c170 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -612,63 +612,119 @@ typedef enum {
typedef ssize_t (*gd_serialize_t) (struct iovec outmsg, void *args);
-#define GLUSTERD_GET_VOLUME_DIR(path, volinfo, priv) \
- if (volinfo->is_snap_volume) { \
- snprintf (path, PATH_MAX, "%s/snaps/%s/%s", priv->workdir, \
- volinfo->snapshot->snapname, volinfo->volname); \
- } else { \
- snprintf (path, PATH_MAX, "%s/vols/%s", priv->workdir, \
- volinfo->volname); \
- }
+#define GLUSTERD_GET_VOLUME_DIR(path, volinfo, priv) \
+ do { \
+ int32_t len; \
+ if (volinfo->is_snap_volume) { \
+ len = snprintf (path, PATH_MAX, "%s/snaps/%s/%s", \
+ priv->workdir, \
+ volinfo->snapshot->snapname, \
+ volinfo->volname); \
+ } else { \
+ len = snprintf (path, PATH_MAX, "%s/vols/%s", \
+ priv->workdir, volinfo->volname); \
+ } \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
+ } while (0)
+
#define GLUSTERD_GET_TIER_DIR(path, volinfo, priv) do { \
- snprintf (path, PATH_MAX, "%s/tier/%s", priv->workdir, \
- volinfo->volname); \
+ int32_t len; \
+ len = snprintf (path, PATH_MAX, "%s/tier/%s", \
+ priv->workdir, volinfo->volname); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
} while (0)
#define GLUSTERD_GET_TIER_PID_FILE(path, volinfo, priv) do { \
char tier_path[PATH_MAX]; \
+ int32_t len; \
GLUSTERD_GET_TIER_DIR(tier_path, volinfo, priv); \
- snprintf (path, PATH_MAX, "%s/run/%s-tierd.pid", tier_path,\
- volinfo->volname); \
+ len = snprintf (path, PATH_MAX, "%s/run/%s-tierd.pid", \
+ tier_path, volinfo->volname); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
} while (0)
#define GLUSTERD_GET_VOLUME_PID_DIR(path, volinfo, priv) \
do { \
+ int32_t len; \
if (volinfo->is_snap_volume) { \
- snprintf (path, PATH_MAX, "%s/snaps/%s/%s", \
- priv->rundir, \
- volinfo->snapshot->snapname, volinfo->volname); \
+ len = snprintf (path, PATH_MAX, "%s/snaps/%s/%s", \
+ priv->rundir, \
+ volinfo->snapshot->snapname, \
+ volinfo->volname); \
} else { \
- snprintf (path, PATH_MAX, "%s/vols/%s", \
- priv->rundir, \
- volinfo->volname); \
+ len = snprintf (path, PATH_MAX, "%s/vols/%s", \
+ priv->rundir, \
+ volinfo->volname); \
+ } \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
} \
} while (0)
-#define GLUSTERD_GET_SNAP_DIR(path, snap, priv) \
- snprintf (path, PATH_MAX, "%s/snaps/%s", priv->workdir, \
- snap->snapname);
+#define GLUSTERD_GET_SNAP_DIR(path, snap, priv) \
+ do { \
+ int32_t len; \
+ len = snprintf (path, PATH_MAX, "%s/snaps/%s", priv->workdir, \
+ snap->snapname); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_GET_SNAP_GEO_REP_DIR(path, snap, priv) \
- snprintf (path, PATH_MAX, "%s/snaps/%s/%s", priv->workdir, \
- snap->snapname, GEOREP);
+ do { \
+ int32_t len; \
+ len = snprintf (path, PATH_MAX, "%s/snaps/%s/%s", \
+ priv->workdir, snap->snapname, GEOREP); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_GET_BRICK_DIR(path, volinfo, priv) \
- if (volinfo->is_snap_volume) { \
- snprintf (path, PATH_MAX, "%s/snaps/%s/%s/%s", priv->workdir, \
- volinfo->snapshot->snapname, volinfo->volname, \
- GLUSTERD_BRICK_INFO_DIR); \
- } else { \
- snprintf (path, PATH_MAX, "%s/%s/%s/%s", priv->workdir, \
- GLUSTERD_VOLUME_DIR_PREFIX, volinfo->volname, \
- GLUSTERD_BRICK_INFO_DIR); \
- }
+ do { \
+ int32_t len; \
+ if (volinfo->is_snap_volume) { \
+ len = snprintf (path, PATH_MAX, "%s/snaps/%s/%s/%s", \
+ priv->workdir, \
+ volinfo->snapshot->snapname, \
+ volinfo->volname, \
+ GLUSTERD_BRICK_INFO_DIR); \
+ } else { \
+ len = snprintf (path, PATH_MAX, "%s/%s/%s/%s", \
+ priv->workdir, \
+ GLUSTERD_VOLUME_DIR_PREFIX, \
+ volinfo->volname, \
+ GLUSTERD_BRICK_INFO_DIR); \
+ } \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_GET_NFS_DIR(path, priv) \
- snprintf (path, PATH_MAX, "%s/nfs", priv->workdir);
+ do { \
+ int32_t len; \
+ len = snprintf (path, PATH_MAX, "%s/nfs", priv->workdir); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_GET_QUOTAD_DIR(path, priv) \
- snprintf (path, PATH_MAX, "%s/quotad", priv->workdir);
+ do { \
+ int32_t len; \
+ len = snprintf (path, PATH_MAX, "%s/quotad", priv->workdir); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_GET_QUOTA_LIMIT_MOUNT_PATH(abspath, volname, path) do { \
snprintf (abspath, sizeof (abspath)-1, \
@@ -697,32 +753,48 @@ do { \
#define GLUSTERD_GET_BRICK_PIDFILE(pidfile,volinfo,brickinfo, priv) do { \
char exp_path[PATH_MAX] = {0,}; \
char volpath[PATH_MAX] = {0,}; \
+ int32_t len = 0; \
GLUSTERD_GET_VOLUME_PID_DIR (volpath, volinfo, priv); \
GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, exp_path); \
- snprintf (pidfile, PATH_MAX, "%s/%s-%s.pid", \
- volpath, brickinfo->hostname, exp_path); \
+ len = snprintf (pidfile, PATH_MAX, "%s/%s-%s.pid", \
+ volpath, brickinfo->hostname, exp_path); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ pidfile[0] = 0; \
+ } \
} while (0)
-#define GLUSTERD_GET_NFS_PIDFILE(pidfile, nfspath, priv) { \
- snprintf (pidfile, PATH_MAX, "%s/nfs/nfs.pid", \
- priv->rundir); \
- }
+#define GLUSTERD_GET_NFS_PIDFILE(pidfile, nfspath, priv) do { \
+ int32_t len; \
+ len = snprintf (pidfile, PATH_MAX, "%s/nfs/nfs.pid", \
+ priv->rundir); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ pidfile[0] = 0; \
+ } \
+ } while (0)
-#define GLUSTERD_GET_QUOTAD_PIDFILE(pidfile, quotadpath, priv) { \
- snprintf (pidfile, PATH_MAX, "%s/quotad/quotad.pid", \
- priv->rundir); \
- }
+#define GLUSTERD_GET_QUOTAD_PIDFILE(pidfile, quotadpath, priv) do { \
+ int32_t len; \
+ len = snprintf (pidfile, PATH_MAX, "%s/quotad/quotad.pid", \
+ priv->rundir); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ pidfile[0] = 0; \
+ } \
+ } while (0)
#define GLUSTERD_GET_QUOTA_CRAWL_PIDDIR(piddir, volinfo, type) do { \
char _volpath[PATH_MAX] = {0,}; \
+ int32_t len; \
GLUSTERD_GET_VOLUME_DIR (_volpath, volinfo, priv); \
if (type == GF_QUOTA_OPTION_TYPE_ENABLE || \
type == GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS) \
- snprintf (piddir, PATH_MAX, "%s/run/quota/enable", \
- _volpath); \
+ len = snprintf (piddir, PATH_MAX, \
+ "%s/run/quota/enable", _volpath); \
else \
- snprintf (piddir, PATH_MAX, "%s/run/quota/disable", \
- _volpath); \
+ len = snprintf (piddir, PATH_MAX, \
+ "%s/run/quota/disable", _volpath); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ piddir[0] = 0; \
+ } \
} while (0)
#define GLUSTERD_STACK_DESTROY(frame) do {\
@@ -740,31 +812,49 @@ do { \
#define GLUSTERD_GET_DEFRAG_DIR(path, volinfo, priv) do { \
char vol_path[PATH_MAX]; \
char operation[NAME_MAX]; \
+ int32_t len; \
GLUSTERD_GET_VOLUME_DIR(vol_path, volinfo, priv); \
GLUSTERD_GET_DEFRAG_PROCESS(operation, volinfo); \
- snprintf (path, PATH_MAX, "%s/%s", vol_path, operation);\
+ len = snprintf (path, PATH_MAX, "%s/%s", vol_path, \
+ operation); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
} while (0)
#define GLUSTERD_GET_DEFRAG_SOCK_FILE_OLD(path, volinfo, priv) do { \
char defrag_path[PATH_MAX]; \
+ int32_t len; \
GLUSTERD_GET_DEFRAG_DIR(defrag_path, volinfo, priv); \
- snprintf (path, PATH_MAX, "%s/%s.sock", defrag_path, \
- uuid_utoa(MY_UUID)); \
+ len = snprintf (path, PATH_MAX, "%s/%s.sock", \
+ defrag_path, uuid_utoa(MY_UUID)); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
} while (0)
-#define GLUSTERD_GET_DEFRAG_SOCK_FILE(path, volinfo) do { \
- char operation[NAME_MAX]; \
- GLUSTERD_GET_DEFRAG_PROCESS(operation, volinfo); \
- snprintf (path, UNIX_PATH_MAX, DEFAULT_VAR_RUN_DIRECTORY \
- "/gluster-%s-%s.sock", operation, \
- uuid_utoa(volinfo->volume_id)); \
+#define GLUSTERD_GET_DEFRAG_SOCK_FILE(path, volinfo) do { \
+ char operation[NAME_MAX]; \
+ int32_t len; \
+ GLUSTERD_GET_DEFRAG_PROCESS(operation, volinfo); \
+ len = snprintf (path, UNIX_PATH_MAX, \
+ DEFAULT_VAR_RUN_DIRECTORY \
+ "/gluster-%s-%s.sock", operation, \
+ uuid_utoa(volinfo->volume_id)); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
} while (0)
#define GLUSTERD_GET_DEFRAG_PID_FILE(path, volinfo, priv) do { \
char defrag_path[PATH_MAX]; \
+ int32_t len; \
GLUSTERD_GET_DEFRAG_DIR(defrag_path, volinfo, priv); \
- snprintf (path, PATH_MAX, "%s/%s.pid", defrag_path, \
- uuid_utoa(MY_UUID)); \
+ len = snprintf (path, PATH_MAX, "%s/%s.pid", \
+ defrag_path, uuid_utoa(MY_UUID)); \
+ if ((len < 0) || (len >= PATH_MAX)) { \
+ path[0] = 0; \
+ } \
} while (0)
#define GLUSTERFS_GET_QUOTA_LIMIT_MOUNT_PIDFILE(pidfile, volname) { \
@@ -796,15 +886,11 @@ do { \
} while (0)
#define GLUSTERD_DUMP_PEERS(head, member, xpeers) do { \
- glusterd_peerinfo_t *_peerinfo = NULL; \
- int index = 1; \
- char key[GF_DUMP_MAX_BUF_LEN] = {0,}; \
+ glusterd_peerinfo_t *_peerinfo = NULL; \
+ int index = 1; \
+ char *key = NULL; \
\
- if (!xpeers) \
- snprintf (key, sizeof (key), "glusterd.peer"); \
- else \
- snprintf (key, sizeof (key), \
- "glusterd.xaction_peer"); \
+ key = xpeers ? "glusterd.xaction_peer" : "glusterd.peer"; \
\
rcu_read_lock (); \
cds_list_for_each_entry_rcu (_peerinfo, head, member) { \
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 236f2e61c33..b02adf308ff 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -2687,8 +2687,12 @@ posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path,
(void) snprintf (gpath, PATH_MAX, "%s/.glusterfs/", brick_path);
while (!(__is_root_gfid (pargfid))) {
- snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
- pargfid[0], pargfid[1], uuid_utoa (pargfid));
+ len = snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
+ pargfid[0], pargfid[1], uuid_utoa (pargfid));
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
len = sys_readlink (dir_handle, linkname, PATH_MAX);
if (len < 0) {
@@ -2707,10 +2711,14 @@ posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path,
dir_name = strtok_r (NULL, "/", &saveptr);
if (strlen(pre_dir_name) != 0) { /* Remove '/' at the end */
- snprintf (result, PATH_MAX, "%s/%s", dir_name,
- pre_dir_name);
+ len = snprintf (result, PATH_MAX, "%s/%s", dir_name,
+ pre_dir_name);
} else {
- snprintf (result, PATH_MAX, "%s", dir_name);
+ len = snprintf (result, PATH_MAX, "%s", dir_name);
+ }
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
}
strncpy (pre_dir_name, result, sizeof(pre_dir_name));
@@ -2720,12 +2728,20 @@ posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path,
}
if (bname) {
- snprintf (result1, PATH_MAX, "/%s/%s", result, bname);
+ len = snprintf (result1, PATH_MAX, "/%s/%s", result, bname);
} else {
- snprintf (result1, PATH_MAX, "/%s", result);
+ len = snprintf (result1, PATH_MAX, "/%s", result);
+ }
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
}
*path = gf_strdup (result1);
+ if (*path == NULL) {
+ ret = -1;
+ goto out;
+ }
out:
return ret;