diff options
author | Sumit Bose <sbose@redhat.com> | 2009-05-20 12:08:13 +0200 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-05-21 11:22:21 +1000 |
commit | 2fcedf6dac9dd275adbb0017e53547614df29d93 (patch) | |
tree | 94a290c1514cd2446139e31a6403466018355f73 | |
parent | 11988fc77a06c50c251acec1dc8cc2c275f68310 (diff) | |
download | samba-2fcedf6dac9dd275adbb0017e53547614df29d93.tar.gz samba-2fcedf6dac9dd275adbb0017e53547614df29d93.tar.xz samba-2fcedf6dac9dd275adbb0017e53547614df29d93.zip |
add missing checks on so far ignored return values
Most of these were found during a review by Jim Meyering <meyering@redhat.com>
(This used to be ctdb commit 3aee5ee1deb4a19be3bd3a4ce3abbe09de763344)
-rw-r--r-- | ctdb/client/ctdb_client.c | 14 | ||||
-rw-r--r-- | ctdb/common/cmdline.c | 7 | ||||
-rw-r--r-- | ctdb/common/ctdb_util.c | 1 | ||||
-rw-r--r-- | ctdb/ib/ibw_ctdb.c | 1 | ||||
-rw-r--r-- | ctdb/ib/ibw_ctdb_init.c | 8 | ||||
-rw-r--r-- | ctdb/ib/ibwrapper.c | 4 | ||||
-rw-r--r-- | ctdb/ib/ibwrapper_test.c | 2 | ||||
-rw-r--r-- | ctdb/lib/util/db_wrap.c | 4 | ||||
-rw-r--r-- | ctdb/lib/util/debug.c | 10 | ||||
-rw-r--r-- | ctdb/server/ctdb_daemon.c | 4 | ||||
-rw-r--r-- | ctdb/server/ctdb_logging.c | 35 | ||||
-rw-r--r-- | ctdb/server/ctdb_server.c | 2 | ||||
-rw-r--r-- | ctdb/server/ctdb_takeover.c | 2 | ||||
-rw-r--r-- | ctdb/server/eventscript.c | 6 | ||||
-rw-r--r-- | ctdb/tests/src/ctdb_persistent.c | 10 | ||||
-rw-r--r-- | ctdb/tools/ctdb.c | 32 | ||||
-rw-r--r-- | ctdb/utils/ping_pong/ping_pong.c | 17 |
17 files changed, 136 insertions, 23 deletions
diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index df9fa063551..7915a936ef2 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -2336,6 +2336,7 @@ int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb, len = offsetof(struct ctdb_all_public_ips, ips) + ipsv4->num*sizeof(struct ctdb_public_ip); *ips = talloc_zero_size(mem_ctx, len); + CTDB_NO_MEMORY(ctdb, *ips); (*ips)->num = ipsv4->num; for (i=0; i<ipsv4->num; i++) { (*ips)->ips[i].pnn = ipsv4->ips[i].pnn; @@ -2708,14 +2709,24 @@ int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb, */ struct ctdb_context *ctdb_init(struct event_context *ev) { + int ret; struct ctdb_context *ctdb; ctdb = talloc_zero(ev, struct ctdb_context); + if (ctdb == NULL) { + DEBUG(DEBUG_ERR,(__location__ " talloc_zero failed.\n")); + return NULL; + } ctdb->ev = ev; ctdb->idr = idr_init(ctdb); CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr); - ctdb_set_socketname(ctdb, CTDB_PATH); + ret = ctdb_set_socketname(ctdb, CTDB_PATH); + if (ret != 0) { + DEBUG(DEBUG_ERR,(__location__ " ctdb_set_socketname failed.\n")); + talloc_free(ctdb); + return NULL; + } return ctdb; } @@ -2735,6 +2746,7 @@ void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags) int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname) { ctdb->daemon.name = talloc_strdup(ctdb, socketname); + if (ctdb->daemon.name == NULL) return -1; return 0; } diff --git a/ctdb/common/cmdline.c b/ctdb/common/cmdline.c index 2136bf637b5..3acbf96e130 100644 --- a/ctdb/common/cmdline.c +++ b/ctdb/common/cmdline.c @@ -117,7 +117,12 @@ struct ctdb_context *ctdb_cmdline_client(struct event_context *ev) /* tell ctdb the socket address */ socket_name = getenv("CTDB_SOCKET"); if (socket_name != NULL) { - ctdb_set_socketname(ctdb, socket_name); + ret = ctdb_set_socketname(ctdb, socket_name); + if (ret == -1) { + printf("ctdb_set_socketname failed - %s\n", + ctdb_errstr(ctdb)); + exit(1); + } } if (ctdb_cmdline.socketname != NULL) { diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c index 3604cc8ed4b..21810924d0b 100644 --- a/ctdb/common/ctdb_util.c +++ b/ctdb/common/ctdb_util.c @@ -73,6 +73,7 @@ int ctdb_parse_address(struct ctdb_context *ctdb, endservent(); address->address = talloc_strdup(mem_ctx, str); + if (address->address == NULL) return -1; if (se == NULL) { address->port = CTDB_PORT; } else { diff --git a/ctdb/ib/ibw_ctdb.c b/ctdb/ib/ibw_ctdb.c index fd577ffdce4..05541ada810 100644 --- a/ctdb/ib/ibw_ctdb.c +++ b/ctdb/ib/ibw_ctdb.c @@ -166,6 +166,7 @@ int ctdb_ibw_receive_handler(struct ibw_conn *conn, void *buf, int n) * and being reused for next receive * noticed that HL requires talloc-ed memory to be stolen */ buf2 = talloc_zero_size(conn, n); + if (buf2 == NULL) return -1; memcpy(buf2, buf, n); ctdb->upcalls->recv_pkt(ctdb, (uint8_t *)buf2, (uint32_t)n); diff --git a/ctdb/ib/ibw_ctdb_init.c b/ctdb/ib/ibw_ctdb_init.c index 2f4fbfe3f26..fa2ddda5aff 100644 --- a/ctdb/ib/ibw_ctdb_init.c +++ b/ctdb/ib/ibw_ctdb_init.c @@ -164,7 +164,15 @@ static int ctdb_ibw_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t le rc = ctdb_ibw_send_pkt(cn->conn, data, length); } else { struct ctdb_ibw_msg *p = talloc_zero(cn, struct ctdb_ibw_msg); + if (p == NULL) { + DEBUG(DEBUG_ERR, ("talloc_zero failed.\n")); + return -1; + } p->data = talloc_memdup(p, data, length); + if (p->data == NULL) { + DEBUG(DEBUG_ERR, ("talloc_memdup failed.\n")); + return -1; + } p->length = length; DLIST_ADD_AFTER(cn->queue, p, cn->queue_last); diff --git a/ctdb/ib/ibwrapper.c b/ctdb/ib/ibwrapper.c index 5a166e5353f..6a557cbb4de 100644 --- a/ctdb/ib/ibwrapper.c +++ b/ctdb/ib/ibwrapper.c @@ -852,7 +852,7 @@ static int ibw_wc_recv(struct ibw_conn *conn, struct ibv_wc *wc) } if (part->to_read==0) { - pctx->receive_func(conn, part->buf, part->len); + if(pctx->receive_func(conn, part->buf, part->len)) goto error; part->len = 0; /* tells not having partial data (any more) */ if (ibw_wc_mem_threshold(pconn, part, pctx->opts.recv_threshold)) goto error; @@ -867,7 +867,7 @@ static int ibw_wc_recv(struct ibw_conn *conn, struct ibv_wc *wc) /* mostly awaited case: */ if (msglen<=remain) { - pctx->receive_func(conn, p, msglen); + if(pctx->receive_func(conn, p, msglen)) goto error; p += msglen; remain -= msglen; } else { diff --git a/ctdb/ib/ibwrapper_test.c b/ctdb/ib/ibwrapper_test.c index cbd4f431738..b9c80ae2ae2 100644 --- a/ctdb/ib/ibwrapper_test.c +++ b/ctdb/ib/ibwrapper_test.c @@ -486,6 +486,7 @@ int ibwtest_getdests(struct ibwtest_ctx *tcx, char op) char *tmp; tmp = talloc_strdup(tcx, optarg); + if (tmp == NULL) return -1; /* hack to reuse the above ibw_initattr parser */ if (ibwtest_parse_attrs(tcx, tmp, &attrs, &tcx->naddrs, op)) return -1; @@ -567,6 +568,7 @@ int main(int argc, char *argv[]) break; case 'o': tcx->opts = talloc_strdup(tcx, optarg); + if (tcx->opts) goto cleanup; if (ibwtest_parse_attrs(tcx, tcx->opts, &tcx->attrs, &tcx->nattrs, op)) goto cleanup; diff --git a/ctdb/lib/util/db_wrap.c b/ctdb/lib/util/db_wrap.c index f4e89cf270f..7f5240e9328 100644 --- a/ctdb/lib/util/db_wrap.c +++ b/ctdb/lib/util/db_wrap.c @@ -82,6 +82,10 @@ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, } w->name = talloc_strdup(w, name); + if (w->name == NULL) { + talloc_free(w); + return NULL; + } w->tdb = tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL); diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 341a4a1586a..9e819292200 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -28,8 +28,14 @@ static void _do_debug_v(const char *format, va_list ap) char *s = NULL; struct tm *tm; char tbuf[100]; - - vasprintf(&s, format, ap); + int ret; + + ret = vasprintf(&s, format, ap); + if (ret == -1) { + fprintf(stderr, "vasprintf failed in _do_debug_v, cannot print debug message.\n"); + fflush(stderr); + return; + } t = timeval_current(); tm = localtime(&t.tv_sec); diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index 8a3f564aa5d..957f5d8d113 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -690,6 +690,10 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork) /* ensure the socket is deleted on exit of the daemon */ domain_socket_name = talloc_strdup(talloc_autofree_context(), ctdb->daemon.name); + if (domain_socket_name == NULL) { + DEBUG(DEBUG_ALERT,(__location__ " talloc_strdup failed.\n")); + exit(12); + } talloc_set_destructor(domain_socket_name, unlink_destructor); ctdb->ev = event_context_init(NULL); diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index f9aa13a3c67..3700a33436b 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -80,20 +80,29 @@ static void ctdb_logfile_log(const char *format, va_list ap) struct tm *tm; char tbuf[100]; char *s2 = NULL; + int ret; - vasprintf(&s, format, ap); + ret = vasprintf(&s, format, ap); + if (ret == -1) { + write(log_state->fd, "vasprintf failed\n", strlen("vasprintf failed\n")); + return; + } t = timeval_current(); tm = localtime(&t.tv_sec); strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm); - asprintf(&s2, "%s.%06u [%5u]: %s", + ret = asprintf(&s2, "%s.%06u [%5u]: %s", tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s); free(s); + if (ret == -1) { + write(log_state->fd, "asprintf failed\n", strlen("asprintf failed\n")); + return; + } if (s2) { write(log_state->fd, s2, strlen(s2)); - free(s2); + free(s2); } } @@ -102,6 +111,7 @@ static void ctdb_logfile_log(const char *format, va_list ap) */ int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog) { + int ret; ctdb->log = talloc_zero(ctdb, struct ctdb_log_state); if (ctdb->log == NULL) { printf("talloc_zero failed\n"); @@ -117,7 +127,11 @@ int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_sy do_debug_v = ctdb_logfile_log; ctdb->log->fd = 1; /* also catch stderr of subcommands to stdout */ - dup2(1, 2); + ret = dup2(1, 2); + if (ret == -1) { + printf("dup2 failed: %s\n", strerror(errno)); + abort(); + } } else { do_debug_v = ctdb_logfile_log; @@ -193,6 +207,7 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde, int ctdb_set_child_logging(struct ctdb_context *ctdb) { int p[2]; + int ret; if (ctdb->log->fd == 1) { /* not needed for stdout logging */ @@ -213,11 +228,19 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb) close(1); close(2); if (p[1] != 1) { - dup2(p[1], 1); + ret = dup2(p[1], 1); + if (ret == -1) { + printf("dup2 failed: %s\n", strerror(errno)); + return -1; + } close(p[1]); } /* also catch stderr of subcommands to the log */ - dup2(1, 2); + ret = dup2(1, 2); + if (ret == -1) { + printf("dup2 failed: %s\n", strerror(errno)); + return -1; + } return 0; } diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c index a701f753fbb..aea73ecb061 100644 --- a/ctdb/server/ctdb_server.c +++ b/ctdb/server/ctdb_server.c @@ -31,6 +31,7 @@ int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport) { ctdb->transport = talloc_strdup(ctdb, transport); + if (ctdb->transport == NULL) return -1; return 0; } @@ -57,6 +58,7 @@ int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip) int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file) { ctdb->recovery_lock_file = talloc_strdup(ctdb, file); + if (ctdb->recovery_lock_file == NULL) return -1; return 0; } diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 29c0ee67911..9eac660e8d9 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -326,6 +326,7 @@ static void release_ip_callback(struct ctdb_context *ctdb, int status, that the cluster has been reconfigured and they should release any sockets on this IP */ data.dptr = (uint8_t *)talloc_strdup(state, ctdb_addr_to_str(state->addr)); + CTDB_NO_MEMORY_VOID(ctdb, data.dptr); data.dsize = strlen((char *)data.dptr)+1; DEBUG(DEBUG_INFO,(__location__ " sending RELEASE_IP for '%s'\n", data.dptr)); @@ -444,6 +445,7 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb, ctdb_sock_addr *ad vnn = talloc_zero(ctdb, struct ctdb_vnn); CTDB_NO_MEMORY_FATAL(ctdb, vnn); vnn->iface = talloc_strdup(vnn, iface); + CTDB_NO_MEMORY(ctdb, vnn->iface); vnn->public_address = *addr; vnn->public_netmask_bits = mask; vnn->pnn = -1; diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index a30ac3f961c..14cd190693e 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -151,6 +151,7 @@ int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA inda script->next = monitoring_status->scripts; script->name = talloc_strdup(script, name); + CTDB_NO_MEMORY(ctdb, script->name); script->start = timeval_current(); monitoring_status->scripts = script; @@ -298,6 +299,7 @@ static int ctdb_event_script_v(struct ctdb_context *ctdb, const char *options) char *script; int count; int is_monitor = 0; + char *d_name_dup; if (!strcmp(options, "monitor")) { is_monitor = 1; @@ -409,7 +411,9 @@ static int ctdb_event_script_v(struct ctdb_context *ctdb, const char *options) /* store the event script in the tree */ - trbt_insert32(tree, (num<<16)|count++, talloc_strdup(tree, de->d_name)); + d_name_dup = talloc_strdup(tree, de->d_name); + CTDB_NO_MEMORY(ctdb, d_name_dup); + trbt_insert32(tree, (num<<16)|count++, d_name_dup); } closedir(dir); diff --git a/ctdb/tests/src/ctdb_persistent.c b/ctdb/tests/src/ctdb_persistent.c index 8f0452abad4..325b378ffa3 100644 --- a/ctdb/tests/src/ctdb_persistent.c +++ b/ctdb/tests/src/ctdb_persistent.c @@ -71,6 +71,7 @@ static void check_counters(struct ctdb_context *ctdb, TDB_DATA data) { int i; uint32_t *counters, *old_counters; + unsigned char *tmp_dptr; counters = (uint32_t *)data.dptr; old_counters = (uint32_t *)old_data.dptr; @@ -86,7 +87,14 @@ static void check_counters(struct ctdb_context *ctdb, TDB_DATA data) if (old_data.dsize != data.dsize) { old_data.dsize = data.dsize; - old_data.dptr = talloc_realloc_size(ctdb, old_data.dptr, old_data.dsize); + tmp_dptr = talloc_realloc_size(ctdb, old_data.dptr, old_data.dsize); + if (tmp_dptr == NULL) { + printf("[%4u] ERROR: talloc_realloc_size failed.\n", getpid()); + success = false; + return; + } else { + old_data.dptr = tmp_dptr; + } } memcpy(old_data.dptr, data.dptr, data.dsize); diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index b85354c0019..57e1a8dffe3 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -424,6 +424,7 @@ static int control_xpnn(struct ctdb_context *ctdb, int argc, const char **argv) pnn_node = talloc(mem_ctx, struct pnn_node); pnn_node->pnn = pnn++; pnn_node->addr = talloc_strdup(pnn_node, node); + CTDB_NO_MEMORY(ctdb, pnn_node->addr); pnn_node->next = pnn_nodes; pnn_nodes = pnn_node; } @@ -597,6 +598,7 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a } natgw_node = talloc(ctdb, struct natgw_node); natgw_node->addr = talloc_strdup(natgw_node, node); + CTDB_NO_MEMORY(ctdb, natgw_node->addr); natgw_node->next = natgw_nodes; natgw_nodes = natgw_node; } @@ -2364,7 +2366,8 @@ static int control_backupdb(struct ctdb_context *ctdb, int argc, const char **ar struct db_file_header dbhdr; struct ctdb_db_context *ctdb_db; struct backup_data *bd; - int fh; + int fh = -1; + int status = -1; if (argc != 2) { DEBUG(DEBUG_ERR,("Invalid arguments\n")); @@ -2397,6 +2400,7 @@ static int control_backupdb(struct ctdb_context *ctdb, int argc, const char **ar ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0); if (ctdb_db == NULL) { DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0])); + talloc_free(tmp_ctx); return -1; } @@ -2449,16 +2453,30 @@ static int control_backupdb(struct ctdb_context *ctdb, int argc, const char **ar dbhdr.size = bd->len; if (strlen(argv[0]) >= MAX_DB_NAME) { DEBUG(DEBUG_ERR,("Too long dbname\n")); - talloc_free(tmp_ctx); - return -1; + goto done; } strncpy(discard_const(dbhdr.name), argv[0], MAX_DB_NAME); - write(fh, &dbhdr, sizeof(dbhdr)); - write(fh, bd->records, bd->len); + ret = write(fh, &dbhdr, sizeof(dbhdr)); + if (ret == -1) { + DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno))); + goto done; + } + ret = write(fh, bd->records, bd->len); + if (ret == -1) { + DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno))); + goto done; + } - close(fh); + status = 0; +done: + if (fh != -1) { + ret = close(fh); + if (ret == -1) { + DEBUG(DEBUG_ERR,("close failed: %s\n", strerror(errno))); + } + } talloc_free(tmp_ctx); - return 0; + return status; } /* diff --git a/ctdb/utils/ping_pong/ping_pong.c b/ctdb/utils/ping_pong/ping_pong.c index 90692e59ecc..27ff0577ac1 100644 --- a/ctdb/utils/ping_pong/ping_pong.c +++ b/ctdb/utils/ping_pong/ping_pong.c @@ -92,16 +92,29 @@ static void ping_pong(int fd, int num_locks) unsigned char *val; unsigned char incr=0, last_incr=0; unsigned char *p = NULL; + int ret; - ftruncate(fd, num_locks+1); + ret = ftruncate(fd, num_locks+1); + if (ret == -1) { + printf("ftruncate failed: %s\n", strerror(errno)); + return; + } if (use_mmap) { p = mmap(NULL, num_locks+1, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (p == MAP_FAILED) { + printf("mmap failed: %s\n", strerror(errno)); + return; + } } val = (unsigned char *)calloc(num_locks+1, sizeof(unsigned char)); + if (val == NULL) { + printf("calloc failed\n"); + return; + } - start_timer(); + start_timer(); lock_range(fd, 0, 1); i = 0; |