summaryrefslogtreecommitdiffstats
path: root/xlators/features
diff options
context:
space:
mode:
authorXavi Hernandez <xhernandez@redhat.com>2018-07-06 20:23:35 +0200
committerXavi Hernandez <xhernandez@redhat.com>2018-07-10 16:28:24 +0200
commit6dc5dfef819cad69d6d4b4c1c305efa74236ad84 (patch)
tree6b325caf478689d8113279191ca1916e5f5b32ea /xlators/features
parent03f1f5bdc46076178f1afdf8e2a76c5b973fe11f (diff)
Fix compile warnings
This patch fixes compile warnings that appear with newer compilers. The solution applied is only to remove the warnings, but it doesn't always solve the problem in the best way. It assumes that the problem will never happen, as the previous code assumed. Change-Id: I6e8470d6c2e2dbd3bd7d324b5fd2f92ffdc3d6ec updates: bz#1193929 Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
Diffstat (limited to 'xlators/features')
-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
3 files changed, 52 insertions, 14 deletions
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)) {