r6741: prevent talloc_strndup() from reading one byte past the end of a buffer,
[samba.git] / 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; }