diff options
author | Michael Adam <obnox@samba.org> | 2014-09-29 12:27:37 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-09-30 16:36:10 +0200 |
commit | 67684dc69585559fae6718837bf6c5ba83af267f (patch) | |
tree | 1297f33e01882102eb8db522e267cced93936b63 | |
parent | a96f0f4c3bd66cb44f882a836bf80b2ce39523e0 (diff) | |
download | samba-67684dc69585559fae6718837bf6c5ba83af267f.tar.gz |
s3:unix_msg: simplify queue_msg() by moving space calculations up.
This allows for early direct return instead of the goto invalid,
since the fds_copy array is filled later.
Pair-Programmed-With: Volker Lendecke <vl@samba.org>
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r-- | source3/lib/unix_msg/unix_msg.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 87265757776..9fdb7c16e44 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -462,29 +462,17 @@ static int queue_msg(struct unix_dgram_send_queue *q, return EINVAL; } - for (i = 0; i < num_fds; i++) { - fds_copy[i] = -1; - } - - for (i = 0; i < num_fds; i++) { - fds_copy[i] = dup(fds[i]); - if (fds_copy[i] == -1) { - ret = errno; - goto fail; - } - } + msglen = sizeof(struct unix_dgram_msg); data_len = iov_buflen(iov, iovlen); if (data_len == -1) { - goto invalid; + return EINVAL; } - msglen = sizeof(struct unix_dgram_msg); - tmp = msglen + data_len; if ((tmp < msglen) || (tmp < data_len)) { /* overflow */ - goto invalid; + return EINVAL; } msglen = tmp; @@ -494,7 +482,7 @@ static int queue_msg(struct unix_dgram_send_queue *q, tmp = msglen + fds_align; if ((tmp < msglen) || (tmp < fds_align)) { /* overflow */ - goto invalid; + return EINVAL; } tmp &= ~fds_align; @@ -504,11 +492,23 @@ static int queue_msg(struct unix_dgram_send_queue *q, tmp = msglen + fds_size; if ((tmp < msglen) || (tmp < fds_size)) { /* overflow */ - goto invalid; + return EINVAL; } msglen = tmp; } + for (i = 0; i < num_fds; i++) { + fds_copy[i] = -1; + } + + for (i = 0; i < num_fds; i++) { + fds_copy[i] = dup(fds[i]); + if (fds_copy[i] == -1) { + ret = errno; + goto fail; + } + } + msg = malloc(msglen); if (msg == NULL) { ret = ENOMEM; @@ -543,8 +543,6 @@ static int queue_msg(struct unix_dgram_send_queue *q, DLIST_ADD_END(q->msgs, msg, struct unix_dgram_msg); return 0; -invalid: - ret = EINVAL; fail: close_fd_array(fds_copy, num_fds); return ret; |