r6741: prevent talloc_strndup() from reading one byte past the end of a buffer,
authorAndrew Tridgell <tridge@samba.org>
Thu, 12 May 2005 02:54:42 +0000 (02:54 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:40 +0000 (13:16 -0500)
giving valgrind errors

source/lib/talloc/talloc.c

index 3650ab7f51b7469aca378a6bf8ebe5b54a776a0d..46abd89bac5e49c64ee05dc49abb8c8d8c59e294 100644 (file)
@@ -919,7 +919,7 @@ char *talloc_strndup(const void *t, const char *p, size_t n)
        size_t len;
        char *ret;
 
-       for (len=0; p[len] && len<n; len++) ;
+       for (len=0; len<n && p[len]; len++) ;
 
        ret = _talloc(t, len + 1);
        if (!ret) { return NULL; }