tCheck malloc and use snprintf in for loop. - git-restrict - simple utility for git repo permission management
HTML git clone https://git.parazyd.org/git-restrict
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 519b8e62121e2f23966f8133d0384710af8c21e7
DIR parent e5234c68bbc2fc29304994afba04eb5a1c9b86d6
HTML Author: parazyd <parazyd@dyne.org>
Date: Wed, 31 Mar 2021 10:50:38 +0200
Check malloc and use snprintf in for loop.
Diffstat:
M git-restrict.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
---
DIR diff --git a/git-restrict.c b/git-restrict.c
t@@ -49,8 +49,12 @@ int main(int argc, char *argv[])
repo[strlen(repo) - 1] = 0;
for (i = 1; i < argc; i++) {
- buf = malloc(strlen(repo) + 4);
- sprintf(buf, "%s.git", argv[i]);
+ if ((buf = malloc(strlen(repo) + 4)) == NULL) {
+ perror("malloc");
+ return 1;
+ }
+
+ snprintf(buf, strlen(repo) + 4, "%s.git", argv[i]);
if (!strcmp(argv[i], repo) || !strcmp(buf, repo)) {
authorized = 1;