mirror of
https://github.com/samba-team/samba.git
synced 2025-03-11 16:58:40 +03:00
ctdb-tools: Fix CID 1539212 - signed/unsigned issue
>>> CID 1539212: Control flow issues (NO_EFFECT) >>> This greater-than-or-equal-to-zero comparison of an unsigned value is always true. "p >= 0UL". 216 while (p >= 0 && output[p] == '\n') { This is a real problem in the unlikely event that the output contains only newlines. Fix the issue by using a pointer and add a test to cover this case. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15438 Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
3452b0d2ce
commit
f01a179abc
@ -203,7 +203,6 @@ static void print_status_one(struct ctdb_event_script *script)
|
||||
const char *t = script->output == NULL ? "" : script->output;
|
||||
size_t len = strlen(t);
|
||||
char output[len+1];
|
||||
size_t p;
|
||||
char *t1, *t2;
|
||||
|
||||
strlcpy(output, t, sizeof(output));
|
||||
@ -212,10 +211,10 @@ static void print_status_one(struct ctdb_event_script *script)
|
||||
* Strip trailing newlines, they are clutter and
|
||||
* interfere with multi-line detection
|
||||
*/
|
||||
p = len - 1;
|
||||
while (p >= 0 && output[p] == '\n') {
|
||||
output[p] = '\0';
|
||||
p--;
|
||||
t1 = output + len - 1;
|
||||
while (t1 >= output && *t1 == '\n') {
|
||||
*t1 = '\0';
|
||||
t1--;
|
||||
}
|
||||
|
||||
/* If the output is a single line then print it inline */
|
||||
|
@ -24,6 +24,14 @@ EOF
|
||||
printf 'No trailing newline'
|
||||
exit 0
|
||||
;;
|
||||
"verbosenewlinesonly")
|
||||
cat <<EOF
|
||||
|
||||
|
||||
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
"verbosefailure") echo "args: $*"; exit 1 ;;
|
||||
"verbosemultilinefailure")
|
||||
cat <<EOF
|
||||
|
@ -56,6 +56,16 @@ ok <<EOF
|
||||
EOF
|
||||
simple_test status random verbosemultilinenonl
|
||||
|
||||
ok_null
|
||||
simple_test run 10 random verbosenewlinesonly
|
||||
|
||||
ok <<EOF
|
||||
01.disabled DISABLED
|
||||
02.enabled OK DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status random verbosenewlinesonly
|
||||
|
||||
required_result 8 <<EOF
|
||||
Event verbosemultilinefailure in random failed
|
||||
EOF
|
||||
|
Loading…
x
Reference in New Issue
Block a user