diff options
author | Aravinda VK <avishwan@redhat.com> | 2017-11-08 16:15:43 +0530 |
---|---|---|
committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-11-13 16:29:10 +0000 |
commit | 7d00abbf57f93cc2e6064d9bc94facbb961335c7 (patch) | |
tree | b2047eeb51424b1ca177bdab47f9881428ed77e2 /xlators/features | |
parent | 2c066c4c365e77421d1009851144efae0b028628 (diff) |
features/libgfchangelog: Fix coverity issues
Error: DEADCODE:
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c:524:
dead_error_begin: Execution cannot reach this statement: "default:".
Error: DEADCODE:
xlators/features/changelog/lib/src/gf-history-changelog.c:984:
dead_error_line: Execution cannot reach the expression "to" inside
this statement: "if (!from || !to)
ret = -1;".
Error: REVERSE_INULL:
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c:678:
check_after_deref: Null-checking "entry" suggests that it may be null,
but it has already been dereferenced on all paths leading to the
check.
Error: STACK_USE:
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c:275:
stack_use_local_overflow: Local variable "ascii" uses 12288 bytes of
stack space, which exceeds the maximum single use of 10000 bytes.
Error: STACK_USE:
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c:167:
stack_use_local_overflow: Local variable "ascii" uses 12288 bytes of
stack space, which exceeds the maximum single use of 10000 bytes.
Error: STRING_NULL:
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c:589:9:
string_null_sink_parm_call: Passing parameter "from_path" to "open"
which expects a null-terminated string.
Error: UNUSED_VALUE:
xlators/features/changelog/lib/src/gf-history-changelog.c:628:
assigned_value: Assigning value "-1" to "ret" here, but that stored
value is overwritten before it can be used.
Error: STRING_NULL:
xlators/features/changelog/lib/src/gf-history-changelog.c:518:
string_null_argument: Function "sys_pread" does not terminate string
"*ccd->changelog".
BUG: 789278
Change-Id: I1414ec6d4a118ce0c14df4dbe50995c85fe3ecf7
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Diffstat (limited to 'xlators/features')
-rw-r--r-- | xlators/features/changelog/lib/src/gf-changelog-journal-handler.c | 45 | ||||
-rw-r--r-- | xlators/features/changelog/lib/src/gf-history-changelog.c | 6 |
2 files changed, 16 insertions, 35 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c index 46f9bdae92c..07de76e7cda 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c +++ b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c @@ -164,7 +164,9 @@ gf_changelog_parse_binary (xlator_t *this, char current_mover = ' '; size_t blen = 0; int parse_err = 0; - char ascii[LINE_BUFSIZE] = {0,}; + char *ascii = NULL; + + ascii = GF_CALLOC (LINE_BUFSIZE, sizeof(char), gf_common_mt_char); nleft = stbuf->st_size; @@ -245,6 +247,8 @@ gf_changelog_parse_binary (xlator_t *this, CHANGELOG_LIB_MSG_MUNMAP_FAILED, "munmap() error"); out: + if (ascii) + GF_FREE (ascii); return ret; } @@ -272,9 +276,11 @@ gf_changelog_parse_ascii (xlator_t *this, char *mover = NULL; int parse_err = 0; char current_mover = ' '; - char ascii[LINE_BUFSIZE] = {0,}; + char *ascii = NULL; const char *fopname = NULL; + ascii = GF_CALLOC (LINE_BUFSIZE, sizeof(char), gf_common_mt_char); + nleft = stbuf->st_size; start = mmap (NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0); @@ -432,32 +438,10 @@ gf_changelog_parse_ascii (xlator_t *this, "munmap() error"); out: - return ret; -} - -#define COPY_BUFSIZE 8192 -static int -gf_changelog_copy (xlator_t *this, int from_fd, int to_fd) -{ - ssize_t size = 0; - char buffer[COPY_BUFSIZE+1] = {0,}; - - while (1) { - size = sys_read (from_fd, buffer, COPY_BUFSIZE); - if (size <= 0) - break; - - if (gf_changelog_write (to_fd, - buffer, size) != size) { - gf_msg (this->name, GF_LOG_ERROR, 0, - CHANGELOG_LIB_MSG_COPY_FROM_BUFFER_FAILED, - "error processing ascii changlog"); - size = -1; - break; - } - } + if (ascii) + GF_FREE (ascii); - return (size < 0 ? -1 : 0); + return ret; } static int @@ -522,8 +506,6 @@ gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl, to_fd, elen, stbuf, version_idx); break; - default: - ret = gf_changelog_copy (this, from_fd, to_fd); } out: @@ -678,7 +660,9 @@ gf_changelog_process (void *data) entry = list_first_entry (&jnl_proc->entries, gf_changelog_entry_t, list); - list_del (&entry->list); + if (entry) + list_del (&entry->list); + jnl_proc->waiting = _gf_false; } pthread_mutex_unlock (&jnl_proc->lock); @@ -708,6 +692,7 @@ gf_changelog_queue_journal (gf_changelog_processor_t *jnl_proc, len = strlen (event->u.journal.path); (void)memcpy (entry->path, event->u.journal.path, len+1); + entry->path[len] = '\0'; pthread_mutex_lock (&jnl_proc->lock); { diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c index 0bf130a0883..0d8289ccc82 100644 --- a/xlators/features/changelog/lib/src/gf-history-changelog.c +++ b/xlators/features/changelog/lib/src/gf-history-changelog.c @@ -517,7 +517,7 @@ gf_changelog_consume_wrap (void* data) ccd->retval = -1; - nread = sys_pread (ccd->fd, ccd->changelog, PATH_MAX, ccd->offset); + nread = sys_pread (ccd->fd, ccd->changelog, PATH_MAX-1, ccd->offset); if (nread < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_READ_ERROR, @@ -628,7 +628,6 @@ gf_history_consume (void * data) gf_msg (this->name, GF_LOG_ERROR, ret, CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED , "could not create consume-thread"); - ret = -1; goto sync; } else n_envoked++; @@ -1004,9 +1003,6 @@ gf_history_changelog (char* changelog_dir, unsigned long start, } } /* end of readdir() */ - if (!from || !to) - ret = -1; - out: if (dirp != NULL) (void) sys_closedir (dirp); |