lib: debug: Avoid negative array access.
authorJeremy Allison <jra@samba.org>
Mon, 17 Apr 2017 21:09:24 +0000 (14:09 -0700)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 18 Apr 2017 09:47:17 +0000 (11:47 +0200)
Report and patch from Hanno Böck <hanno@hboeck.de>.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12746

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/debug.c

index f48daf69553acc4a7266b8f698f618816eaf3e15..5abca41d534028ee01c7f255d6deecaf826f0bbc 100644 (file)
@@ -488,7 +488,7 @@ static void debug_backends_log(const char *msg, int msg_level)
         * a buffer without the newline character.
         */
        len = MIN(strlen(msg), FORMAT_BUFR_SIZE - 1);
-       if (msg[len - 1] == '\n') {
+       if ((len > 0) && (msg[len - 1] == '\n')) {
                len--;
        }