l10n: Update git.pot (1 new messages)
[gitweb.git] / config.c
index ad0390819d2701d6153adf9db2947ee4908742ce..9ef947e073f487c035d0317572fe3733de8f0ad5 100644 (file)
--- a/config.c
+++ b/config.c
@@ -196,8 +196,10 @@ static char *parse_value(void)
        for (;;) {
                int c = get_next_char();
                if (c == '\n') {
-                       if (quote)
+                       if (quote) {
+                               cf->linenr--;
                                return NULL;
+                       }
                        return cf->value.buf;
                }
                if (comment)
@@ -287,7 +289,7 @@ static int get_extended_base_var(char *name, int baselen, int c)
 {
        do {
                if (c == '\n')
-                       return -1;
+                       goto error_incomplete_line;
                c = get_next_char();
        } while (isspace(c));
 
@@ -299,13 +301,13 @@ static int get_extended_base_var(char *name, int baselen, int c)
        for (;;) {
                int c = get_next_char();
                if (c == '\n')
-                       return -1;
+                       goto error_incomplete_line;
                if (c == '"')
                        break;
                if (c == '\\') {
                        c = get_next_char();
                        if (c == '\n')
-                               return -1;
+                               goto error_incomplete_line;
                }
                name[baselen++] = c;
                if (baselen > MAXNAME / 2)
@@ -316,6 +318,9 @@ static int get_extended_base_var(char *name, int baselen, int c)
        if (get_next_char() != ']')
                return -1;
        return baselen;
+error_incomplete_line:
+       cf->linenr--;
+       return -1;
 }
 
 static int get_base_var(char *name)
@@ -1547,20 +1552,42 @@ static int section_name_match (const char *buf, const char *name)
        return 0;
 }
 
+static int section_name_is_ok(const char *name)
+{
+       /* Empty section names are bogus. */
+       if (!*name)
+               return 0;
+
+       /*
+        * Before a dot, we must be alphanumeric or dash. After the first dot,
+        * anything goes, so we can stop checking.
+        */
+       for (; *name && *name != '.'; name++)
+               if (*name != '-' && !isalnum(*name))
+                       return 0;
+       return 1;
+}
+
 /* if new_name == NULL, the section is removed instead */
 int git_config_rename_section_in_file(const char *config_filename,
                                      const char *old_name, const char *new_name)
 {
        int ret = 0, remove = 0;
        char *filename_buf = NULL;
-       struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1);
+       struct lock_file *lock;
        int out_fd;
        char buf[1024];
        FILE *config_file;
 
+       if (new_name && !section_name_is_ok(new_name)) {
+               ret = error("invalid section name: %s", new_name);
+               goto out;
+       }
+
        if (!config_filename)
                config_filename = filename_buf = git_pathdup("config");
 
+       lock = xcalloc(sizeof(struct lock_file), 1);
        out_fd = hold_lock_file_for_update(lock, config_filename, 0);
        if (out_fd < 0) {
                ret = error("could not lock config file %s", config_filename);