]> asedeno.scripts.mit.edu Git - git.git/blobdiff - config.c
Merge branch 'master' of git://repo.or.cz/git/fastimport
[git.git] / config.c
index 2cd0263e13cab1b445498d82e73d1ca09b0b58f0..d82107124a53bca99ee65ea31dceb3871bf6796f 100644 (file)
--- a/config.c
+++ b/config.c
@@ -269,6 +269,11 @@ int git_default_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.bare")) {
+               is_bare_repository_cfg = git_config_bool(var, value);
+               return 0;
+       }
+
        if (!strcmp(var, "core.ignorestat")) {
                assume_unchanged = git_config_bool(var, value);
                return 0;
@@ -656,6 +661,11 @@ int git_config_set_multivar(const char* key, const char* value,
                                goto out_free;
                        }
                        c = tolower(c);
+               } else if (c == '\n') {
+                       fprintf(stderr, "invalid key (newline): %s\n", key);
+                       free(store.key);
+                       ret = 1;
+                       goto out_free;
                }
                store.key[i] = c;
        }
@@ -694,11 +704,9 @@ int git_config_set_multivar(const char* key, const char* value,
 
                store.key = (char*)key;
                if (!store_write_section(fd, key) ||
-                   !store_write_pair(fd, key, value)) {
-                       ret = write_error();
-                       goto out_free;
-               }
-       } else{
+                   !store_write_pair(fd, key, value))
+                       goto write_err_out;
+       } else {
                struct stat st;
                char* contents;
                int i, copy_begin, copy_end, new_line = 0;
@@ -777,31 +785,33 @@ int git_config_set_multivar(const char* key, const char* value,
 
                        /* write the first part of the config */
                        if (copy_end > copy_begin) {
-                               write_in_full(fd, contents + copy_begin,
-                               copy_end - copy_begin);
-                               if (new_line)
-                                       write_in_full(fd, "\n", 1);
+                               if (write_in_full(fd, contents + copy_begin,
+                                                 copy_end - copy_begin) <
+                                   copy_end - copy_begin)
+                                       goto write_err_out;
+                               if (new_line &&
+                                   write_in_full(fd, "\n", 1) != 1)
+                                       goto write_err_out;
                        }
                        copy_begin = store.offset[i];
                }
 
                /* write the pair (value == NULL means unset) */
                if (value != NULL) {
-                       if (store.state == START)
-                               if (!store_write_section(fd, key)) {
-                                       ret = write_error();
-                                       goto out_free;
-                               }
-                       if (!store_write_pair(fd, key, value)) {
-                               ret = write_error();
-                               goto out_free;
+                       if (store.state == START) {
+                               if (!store_write_section(fd, key))
+                                       goto write_err_out;
                        }
+                       if (!store_write_pair(fd, key, value))
+                               goto write_err_out;
                }
 
                /* write the rest of the config */
                if (copy_begin < st.st_size)
-                       write_in_full(fd, contents + copy_begin,
-                               st.st_size - copy_begin);
+                       if (write_in_full(fd, contents + copy_begin,
+                                         st.st_size - copy_begin) <
+                           st.st_size - copy_begin)
+                               goto write_err_out;
 
                munmap(contents, st.st_size);
                unlink(config_filename);
@@ -824,6 +834,11 @@ out_free:
                free(lock_file);
        }
        return ret;
+
+write_err_out:
+       ret = write_error();
+       goto out_free;
+
 }
 
 int git_config_rename_section(const char *old_name, const char *new_name)
@@ -881,7 +896,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
                                if (buf[i] != old_name[j++])
                                        break;
                        }
-                       if (buf[i] == ']') {
+                       if (buf[i] == ']' && old_name[j] == 0) {
                                /* old_name matches */
                                ret++;
                                store.baselen = strlen(new_name);