From: Martin Schwenke Date: Sun, 30 Jul 2023 01:07:47 +0000 (+1000) Subject: ctdb-tools: Fix CID 1539212 - signed/unsigned issue X-Git-Tag: tevent-0.16.0~1250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f01a179abcb33d9da6097f5ae45c7e7df1bc0397;p=thirdparty%2Fsamba.git 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 Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/event/event_tool.c b/ctdb/event/event_tool.c index e6d5261c217..d6b7156c69b 100644 --- a/ctdb/event/event_tool.c +++ b/ctdb/event/event_tool.c @@ -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 */ diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script index 90df5218a9d..ace80fd8e56 100755 --- a/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script @@ -24,6 +24,14 @@ EOF printf 'No trailing newline' exit 0 ;; +"verbosenewlinesonly") + cat <