mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
Fixes for various issues found by Coverity
Signed-off-by: Amitay Isaacs <amitay@gmail.com> (This used to be ctdb commit 05bfdbbd0d4abdfbcf28e3930086723508b35952)
This commit is contained in:
parent
d039f799ac
commit
157f1cfefd
@ -3315,7 +3315,7 @@ static void async_callback(struct ctdb_client_control_state *state)
|
||||
struct ctdb_context *ctdb = talloc_get_type(state->ctdb, struct ctdb_context);
|
||||
int ret;
|
||||
TDB_DATA outdata;
|
||||
int32_t res;
|
||||
int32_t res = -1;
|
||||
uint32_t destnode = state->c->hdr.destnode;
|
||||
|
||||
/* one more node has responded with recmode data */
|
||||
|
@ -129,7 +129,7 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a
|
||||
tm = localtime(&log_entries[tmp_entry].t.tv_sec);
|
||||
strftime(tbuf, sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
|
||||
|
||||
if (log_entries[tmp_entry].message) {
|
||||
if (log_entries[tmp_entry].message[0] != '\0') {
|
||||
fprintf(f, "%s:%s %s", tbuf,
|
||||
get_debug_by_level(log_entries[tmp_entry].level),
|
||||
log_entries[tmp_entry].message);
|
||||
@ -137,9 +137,17 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a
|
||||
}
|
||||
|
||||
fsize = ftell(f);
|
||||
if (fsize < 0) {
|
||||
fclose(f);
|
||||
DEBUG(DEBUG_ERR, ("Cannot get file size for log entries\n"));
|
||||
return;
|
||||
}
|
||||
rewind(f);
|
||||
data.dptr = talloc_size(NULL, fsize);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
|
||||
if (data.dptr == NULL) {
|
||||
fclose(f);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
|
||||
}
|
||||
data.dsize = fread(data.dptr, 1, fsize, f);
|
||||
fclose(f);
|
||||
|
||||
|
@ -1273,6 +1273,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog,
|
||||
fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd,
|
||||
EVENT_FD_READ,
|
||||
ctdb_accept_client, ctdb);
|
||||
if (fde == NULL) {
|
||||
ctdb_fatal(ctdb, "Failed to add daemon socket to event loop");
|
||||
}
|
||||
tevent_fd_set_auto_close(fde);
|
||||
|
||||
/* release any IPs we hold from previous runs of the daemon */
|
||||
|
@ -547,6 +547,10 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb)
|
||||
/* We'll fail if stderr/stdout not already open; it's simpler. */
|
||||
old_stdout = dup(STDOUT_FILENO);
|
||||
old_stderr = dup(STDERR_FILENO);
|
||||
if (old_stdout < 0 || old_stderr < 0) {
|
||||
DEBUG(DEBUG_ERR, ("Failed to dup stdout/stderr for child logging\n"));
|
||||
return -1;
|
||||
}
|
||||
if (dup2(p[1], STDOUT_FILENO) < 0 || dup2(p[1], STDERR_FILENO) < 0) {
|
||||
int saved_errno = errno;
|
||||
dup2(old_stdout, STDOUT_FILENO);
|
||||
|
@ -1187,7 +1187,10 @@ static int ctdb_attach_persistent(struct ctdb_context *ctdb,
|
||||
int invalid_name = 0;
|
||||
|
||||
s = talloc_strdup(ctdb, de->d_name);
|
||||
CTDB_NO_MEMORY(ctdb, s);
|
||||
if (s == NULL) {
|
||||
closedir(d);
|
||||
CTDB_NO_MEMORY(ctdb, s);
|
||||
}
|
||||
|
||||
/* only accept names ending in .tdb */
|
||||
p = strstr(s, ".tdb.");
|
||||
|
@ -1260,8 +1260,8 @@ static int traverse_recdb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
|
||||
params->recdata = talloc_realloc_size(NULL, params->recdata, params->allocated_len);
|
||||
}
|
||||
if (params->recdata == NULL) {
|
||||
DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u (%u records)\n",
|
||||
rec->length + params->len, params->recdata->count));
|
||||
DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u\n",
|
||||
rec->length + params->len));
|
||||
params->failed = true;
|
||||
return -1;
|
||||
}
|
||||
|
@ -218,6 +218,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
|
||||
tree_item = talloc(tree, struct ctdb_script_tree_item);
|
||||
if (tree_item == NULL) {
|
||||
DEBUG(DEBUG_ERR, (__location__ " Failed to allocate new tree item\n"));
|
||||
closedir(dir);
|
||||
talloc_free(tmp_ctx);
|
||||
return NULL;
|
||||
}
|
||||
@ -230,6 +231,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
|
||||
tree_item->name = talloc_strdup(tree_item, de->d_name);
|
||||
if (tree_item->name == NULL) {
|
||||
DEBUG(DEBUG_ERR,(__location__ " Failed to allocate script name.\n"));
|
||||
closedir(dir);
|
||||
talloc_free(tmp_ctx);
|
||||
return NULL;
|
||||
}
|
||||
@ -880,10 +882,10 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call
|
||||
va_start(ap, fmt);
|
||||
ret = ctdb_event_script_callback_v(ctdb, ctdb,
|
||||
event_script_callback, &status, false, call, fmt, ap);
|
||||
va_end(ap);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
status.status = -1;
|
||||
status.done = false;
|
||||
|
@ -154,6 +154,10 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
|
||||
}
|
||||
|
||||
tnode->fd = socket(sock_out.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (tnode->fd == -1) {
|
||||
DEBUG(DEBUG_ERR, (__location__ "Failed to create socket\n"));
|
||||
return;
|
||||
}
|
||||
set_nonblocking(tnode->fd);
|
||||
set_close_on_exec(tnode->fd);
|
||||
|
||||
@ -196,7 +200,12 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
|
||||
sock_in.ip.sin_len = sockin_size;
|
||||
sock_out.ip.sin_len = sockout_size;
|
||||
#endif
|
||||
bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size);
|
||||
if (bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size) == -1) {
|
||||
DEBUG(DEBUG_ERR, (__location__ "Failed to bind socket %s(%d)\n",
|
||||
strerror(errno), errno));
|
||||
close(tnode->fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (connect(tnode->fd, (struct sockaddr *)&sock_out, sockout_size) != 0 &&
|
||||
errno != EINPROGRESS) {
|
||||
|
@ -83,6 +83,11 @@ static void bench_fetch_1node(struct ctdb_context *ctdb)
|
||||
data.dptr = (uint8_t *)talloc_asprintf_append((char *)data.dptr,
|
||||
"msg_count=%d on node %d\n",
|
||||
msg_count, ctdb_get_pnn(ctdb));
|
||||
if (data.dptr == NULL) {
|
||||
printf("Failed to create record\n");
|
||||
talloc_free(tmp_ctx);
|
||||
return;
|
||||
}
|
||||
data.dsize = strlen((const char *)data.dptr)+1;
|
||||
|
||||
ret = ctdb_record_store(h, data);
|
||||
|
Loading…
Reference in New Issue
Block a user