Repository: rsyslog/rsyslog (2025-08-28T10:26:55Z)

Issue:
rainerscript: random() function does not provide user-visible warning when passed an unsupported value
### Expected behavior

1. Call `random()` function a value larger than what the underlying platform supports
1. A warning is emitted to debug and "normal" output

### Actual behavior

1. Call `random()` function a value larger than what the underlying platform supports
1. A warning is emitted to debug output only

### Steps to reproduce the behavior

1. Build current master
1. Enable debug logging
1. Call the `random()` function with a value larger than the platform supports

### Environment
- rsyslog version: current master


See also rsyslog/rsyslog-doc#460



Discussion:

Patch:
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index 82638305f4..b435b393f3 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -1994,6 +1994,9 @@ static void ATTR_NONNULL() doFunct_RandomGen(struct cnffunc *__restrict__ const
             "rainerscript: desired random-number range [0 - %lld] "
             "is wider than supported limit of [0 - %d)\n",
             max, MAX_RANDOM_NUMBER);
+        LogError(0, RS_RET_VALUE_NOT_SUPPORTED,
+                 "rainerscript: desired random-number range [0 - %lld] is wider than supported limit of [0 - %d)", max,
+                 MAX_RANDOM_NUMBER);
     }
 
     retVal = (x % max);


Test patch:
diff --git a/tests/rscript_random_warning.sh b/tests/rscript_random_warning.sh
new file mode 100755
index 0000000000..02eeae58d0
--- /dev/null
+++ b/tests/rscript_random_warning.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+## rscript_random_warning.sh
+## Verify that random() warns when max exceeds platform limit
+. ${srcdir:=.}/diag.sh init
+export RS_REDIR=">rsyslog.log 2>&1"
+
+generate_conf
+add_conf '
+$DebugFile rsyslog.debug.log
+$DebugLevel 2
+
+template(name="outfmt" type="string" string="%$.rand%\n")
+module(load="../plugins/imtcp/.libs/imtcp")
+input(type="imtcp" port="0" listenPortFileName="'${RSYSLOG_DYNNAME}'.tcpflood_port")
+set $.rand = random(4294967296);
+action(type="omfile" file="'${RSYSLOG_OUT_LOG}'" template="outfmt")
+'
+startup
+tcpflood -m 1
+shutdown_when_empty
+wait_shutdown
+WARN="rainerscript: desired random-number range [0 - 4294967296] is wider than supported limit"
+if ! grep -F "$WARN" rsyslog.log > /dev/null; then
+  echo "FAIL: warning not found in rsyslog.log"
+  cat rsyslog.log
+  exit 1
+fi
+if ! grep -F "$WARN" rsyslog.debug.log > /dev/null; then
+  echo "FAIL: warning not found in rsyslog.debug.log"
+  cat rsyslog.debug.log
+  exit 1
+fi
+exit_test