mirror of
https://github.com/samba-team/samba.git
synced 2025-01-03 01:18:10 +03:00
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
This commit is contained in:
parent
7a6bd22798
commit
3aecd6e7b5
@ -97,7 +97,7 @@ bool tmon_set_exit(struct tmon_pkt *pkt)
|
|||||||
|
|
||||||
bool tmon_set_errno(struct tmon_pkt *pkt, int err)
|
bool tmon_set_errno(struct tmon_pkt *pkt, int err)
|
||||||
{
|
{
|
||||||
if (err < 0 && err > UINT16_MAX) {
|
if (err <= 0 || err > UINT16_MAX) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
epipe=$(errcode EPIPE)
|
epipe=$(errcode EPIPE)
|
||||||
etimedout=$(errcode ETIMEDOUT)
|
etimedout=$(errcode ETIMEDOUT)
|
||||||
|
edom=$(errcode EDOM)
|
||||||
|
|
||||||
test_cases()
|
test_cases()
|
||||||
{
|
{
|
||||||
@ -35,6 +36,34 @@ WRITER OK
|
|||||||
EOF
|
EOF
|
||||||
unit_test tmon_test "7" false 0 false
|
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"
|
test_case "Exit packet @ 3s, no timeout"
|
||||||
ok <<EOF
|
ok <<EOF
|
||||||
READER OK
|
READER OK
|
||||||
|
@ -45,6 +45,7 @@ static int test_write_callback(void *private_data, struct tmon_pkt *pkt)
|
|||||||
private_data, struct test_write_state);
|
private_data, struct test_write_state);
|
||||||
bool status;
|
bool status;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
char *end;
|
||||||
int err;
|
int err;
|
||||||
char c;
|
char c;
|
||||||
const char *t;
|
const char *t;
|
||||||
@ -75,6 +76,16 @@ static int test_write_callback(void *private_data, struct tmon_pkt *pkt)
|
|||||||
case '!':
|
case '!':
|
||||||
status = tmon_set_ping(pkt);
|
status = tmon_set_ping(pkt);
|
||||||
break;
|
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:
|
default:
|
||||||
status = false;
|
status = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user