diff options
Diffstat (limited to 'src/edit.c')
| -rw-r--r-- | src/edit.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -194,6 +194,26 @@ static int is_rule_for(const char *line, const char *user, const char *repo) return same; } +// A ref pattern reaches the file as one field. Whitespace would split it into +// two patterns when the file is read back - granting a ref nobody asked for - and +// '#' starts a comment, so the pattern would be quietly cut short. An argument +// carrying either means something other than what was typed. + +static int ref_field_ok(const char *s) +{ + size_t i; + + if (s[0] == '\0') + return 0; + for (i = 0; s[i] != '\0'; i++) { + unsigned char c = (unsigned char)s[i]; + + if (isspace(c) || c == '#') + return 0; + } + return 1; +} + static char *rule_text(const char *user, const char *repo, const char *level, int nrefs, char **refs) { @@ -315,6 +335,7 @@ int cmd_grant(const char *path, edit_opts o, int argc, char **argv) int i; int first = -1; int replaced = -1; + int appended = 0; int dropped = 0; int created = 0; @@ -343,6 +364,10 @@ int cmd_grant(const char *path, edit_opts o, int argc, char **argv) progname, argv[i]); return 64; } + if (!ref_field_ok(argv[i])) { + fprintf(stderr, "%s: not a ref pattern: %s\n", progname, argv[i]); + return 64; + } } if (authz_reject_options(argc, argv) != 0) @@ -382,6 +407,7 @@ int cmd_grant(const char *path, edit_opts o, int argc, char **argv) if (first < 0) { lines_push(&lines, text); // the buffer belongs to the file now replaced = (int)lines.n; + appended = 1; } else { size_t w; @@ -404,7 +430,7 @@ int cmd_grant(const char *path, edit_opts o, int argc, char **argv) else if (dropped > 0) snprintf(what, sizeof(what), "granted %s %s %s (line %d, %d duplicate(s) removed)", argv[0], argv[1], argv[2], replaced, dropped); - else if ((int)lines.n == replaced) + else if (appended) snprintf(what, sizeof(what), "granted %s %s %s (appended as line %d)", argv[0], argv[1], argv[2], replaced); else |
