diff options
author | Martin Schwenke <martin@meltin.net> | 2022-07-30 10:19:56 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2022-08-01 09:19:55 +0000 |
commit | 3aecd6e7b501abfd2c65f8d006a67001f79dd5fc (patch) | |
tree | afa9a8b1327948a4ee9cb367e80660dd5ef9556b /ctdb | |
parent | 7a6bd2279897ed389d10f09e5b315a7bca96e7d4 (diff) | |
download | samba-3aecd6e7b501abfd2c65f8d006a67001f79dd5fc.tar.gz |
ctdb-common: CID 1507498: Control flow issues (DEADCODE)
Fix typo in error checking. While here adjust the bottom of the
range, making errno 0 invalid.
Add corresponding test cases using an alternative syntax for errno packets
(#nnn[;] - trailing ';' is optional).
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Mon Aug 1 09:19:55 UTC 2022 on sn-devel-184
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/common/tmon.c | 2 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/cunit/tmon_test_002.sh | 29 | ||||
-rw-r--r-- | ctdb/tests/src/tmon_test.c | 11 |
3 files changed, 41 insertions, 1 deletions
diff --git a/ctdb/common/tmon.c b/ctdb/common/tmon.c index 87a55e3b1e9..04bad1f3bf4 100644 --- a/ctdb/common/tmon.c +++ b/ctdb/common/tmon.c @@ -97,7 +97,7 @@ bool tmon_set_exit(struct tmon_pkt *pkt) bool tmon_set_errno(struct tmon_pkt *pkt, int err) { - if (err < 0 && err > UINT16_MAX) { + if (err <= 0 || err > UINT16_MAX) { return false; } diff --git a/ctdb/tests/UNIT/cunit/tmon_test_002.sh b/ctdb/tests/UNIT/cunit/tmon_test_002.sh index 97a17a188e5..e4118a3d09a 100755 --- a/ctdb/tests/UNIT/cunit/tmon_test_002.sh +++ b/ctdb/tests/UNIT/cunit/tmon_test_002.sh @@ -4,6 +4,7 @@ epipe=$(errcode EPIPE) etimedout=$(errcode ETIMEDOUT) +edom=$(errcode EDOM) test_cases() { @@ -35,6 +36,34 @@ WRITER OK EOF unit_test tmon_test "7" false 0 false + test_case "errno 110 packet @ 1s, no timeout" + ok <<EOF +READER ERR=110 +WRITER OK +EOF + unit_test tmon_test "#110" false 0 false + + test_case "errno 0 error causes EDOM @ 1s, no timeout" + ok <<EOF +WRITER ERR=$edom +READER ERR=$epipe +EOF + unit_test tmon_test "#0;" false 0 false + + test_case "errno -1 error causes EDOM @ 1s, no timeout" + ok <<EOF +WRITER ERR=$edom +READER ERR=$epipe +EOF + unit_test tmon_test "#-1;" false 0 false + + test_case "errno 70000 error causes EDOM @ 1s, no timeout" + ok <<EOF +WRITER ERR=$edom +READER ERR=$epipe +EOF + unit_test tmon_test "#70000;!0" false 0 false + test_case "Exit packet @ 3s, no timeout" ok <<EOF READER OK diff --git a/ctdb/tests/src/tmon_test.c b/ctdb/tests/src/tmon_test.c index 651c24b7414..fb1f5eb9d30 100644 --- a/ctdb/tests/src/tmon_test.c +++ b/ctdb/tests/src/tmon_test.c @@ -45,6 +45,7 @@ static int test_write_callback(void *private_data, struct tmon_pkt *pkt) private_data, struct test_write_state); bool status; size_t len; + char *end; int err; char c; const char *t; @@ -75,6 +76,16 @@ static int test_write_callback(void *private_data, struct tmon_pkt *pkt) case '!': status = tmon_set_ping(pkt); break; + case '#': + /* Additional errno syntax: #nnn[;] */ + t = &state->write_data[state->offset]; + err = (int)strtol(t, &end, 10); + state->offset += (end - t); + if (state->write_data[state->offset] == ';') { + state->offset++; + } + status = tmon_set_errno(pkt, err); + break; default: status = false; } |