s4:lib:registry: fix 'Conditional jump or move' valgrind error.
authorNoel Power <noel.power@suse.com>
Fri, 15 Apr 2016 11:51:32 +0000 (12:51 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 25 Apr 2016 08:35:14 +0000 (10:35 +0200)
smbtorture local.registry.diff.dotreg.test_diff_apply produces the following
valgrind trace

==18367== Conditional jump or move depends on uninitialised value(s)
==18367==    at 0xA02ED96: reg_dotreg_diff_load (patchfile_dotreg.c:252)
==18367==    by 0xA031C6C: reg_diff_load (patchfile.c:375)
==18367==    by 0xA0323AB: reg_diff_apply (patchfile.c:542)
==18367==    by 0x15F116: test_diff_apply (diff.c:72)
==18367==    by 0x955460C: wrap_test_with_simple_test (torture.c:731)
==18367==    by 0x955366F: internal_torture_run_test (torture.c:442)
==18367==    by 0x9553A4B: torture_run_test_restricted (torture.c:542)
==18367==    by 0x260074: run_matching (smbtorture.c:110)
==18367==    by 0x25FF36: run_matching (smbtorture.c:95)
==18367==    by 0x25FF36: run_matching (smbtorture.c:95)
==18367==    by 0x25FF36: run_matching (smbtorture.c:95)
==18367==    by 0x260195: torture_run_named_tests (smbtorture.c:143)
==18367==

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/lib/registry/patchfile_dotreg.c

index f537b971f7c290c486932f7ac3933e8757ced348..49f71f9a7a605ba18f827785222800364578633b 100644 (file)
@@ -249,7 +249,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
 
        while ((line = afdgets(fd, mem_ctx, 0))) {
                /* Remove '\r' if it's a Windows text file */
-               if (line[strlen(line)-1] == '\r') {
+               if (strlen(line) && line[strlen(line)-1] == '\r') {
                        line[strlen(line)-1] = '\0';
                }