Tidy up some missing checks for NULL in strlcpy.
authorJeremy Allison <jra@samba.org>
Tue, 3 May 2011 23:42:17 +0000 (16:42 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 4 May 2011 19:12:15 +0000 (12:12 -0700)
lib/util/string_wrappers.h
libcli/auth/smbencrypt.c
source3/client/clitar.c

index 4a5f51d96bc057b225fc665f001e6a88bdf18423..80d0b9932aa87f95775a49607fc322715d0ceffe 100644 (file)
@@ -42,7 +42,7 @@ size_t __unsafe_string_function_usage_here_size_t__(void);
 #endif /* HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS */
 
 #define strlcpy_base(dest, src, base, size) \
-    strlcpy(dest, src, size-PTR_DIFF(dest,base))
+    strlcpy((dest), (src) ? (src) : "", (size)-PTR_DIFF((dest),(base)))
 
 /* String copy functions - macro hell below adds 'type checking' (limited,
    but the best we can do in C) */
index c59bc515ba3ac023d37b6225bf11a34978133c0f..0cd836302b627aba48b9fff9a158e4bf22cc57b3 100644 (file)
@@ -134,7 +134,7 @@ bool E_deshash(const char *passwd, uint8_t p16[16])
        tmpbuf = strupper_talloc(mem_ctx, passwd);
        if (tmpbuf == NULL) {
                /* Too many callers don't check this result, we need to fill in the buffer with something */
-               strlcpy((char *)dospwd, passwd, sizeof(dospwd));
+               strlcpy((char *)dospwd, passwd ? passwd : "", sizeof(dospwd));
                E_P16(dospwd, p16);
                return false;
        }
index 61af481e85f61b04451b937dc5799bcbfee8a1f4..80968a64d77ccd9c7b306ddf969603cd36c41d82 100644 (file)
@@ -180,7 +180,7 @@ static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime
        /* write out a "standard" tar format header */
 
        hb.dbuf.name[NAMSIZ-1]='\0';
-       strlcpy(hb.dbuf.mode, amode, sizeof(hb.dbuf.mode));
+       strlcpy(hb.dbuf.mode, amode ? amode : "", sizeof(hb.dbuf.mode));
        oct_it((uint64_t)0, 8, hb.dbuf.uid);
        oct_it((uint64_t)0, 8, hb.dbuf.gid);
        oct_it((uint64_t) size, 13, hb.dbuf.size);