Commit d475dd0dd4e08388c409cffce81082d0fbe3843f

Stefan Sperling 2018-06-04T20:52:43

use strlcpy instead of strncpy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/lib/pack.c b/lib/pack.c
index e4dd851..3d2c3d6 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -506,8 +506,9 @@ get_packfile_path(char **path_packfile, struct got_repository *repo,
 		return got_error_from_errno();
 
 	/* Copy up to and excluding ".idx". */
-	strncpy(*path_packfile, packidx->path_packidx,
-	    size - strlen(".idx") - 2);
+	if (strlcpy(*path_packfile, packidx->path_packidx,
+	    size - strlen(".idx") - 1) >= size)
+		return got_error(GOT_ERR_NO_SPACE);
 
 	if (strlcat(*path_packfile, GOT_PACKFILE_SUFFIX, size) >= size)
 		return got_error(GOT_ERR_NO_SPACE);