rugged 0.27.7 → 0.27.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +6 -2
  4. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
  5. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
  6. data/vendor/libgit2/cmake/Modules/FindIconv.cmake +11 -6
  7. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -2
  8. data/vendor/libgit2/include/git2.h +0 -1
  9. data/vendor/libgit2/include/git2/attr.h +7 -18
  10. data/vendor/libgit2/include/git2/blame.h +22 -39
  11. data/vendor/libgit2/include/git2/blob.h +1 -1
  12. data/vendor/libgit2/include/git2/branch.h +1 -1
  13. data/vendor/libgit2/include/git2/buffer.h +2 -14
  14. data/vendor/libgit2/include/git2/checkout.h +12 -13
  15. data/vendor/libgit2/include/git2/cherrypick.h +4 -6
  16. data/vendor/libgit2/include/git2/clone.h +6 -8
  17. data/vendor/libgit2/include/git2/commit.h +0 -28
  18. data/vendor/libgit2/include/git2/common.h +0 -27
  19. data/vendor/libgit2/include/git2/config.h +0 -1
  20. data/vendor/libgit2/include/git2/describe.h +7 -30
  21. data/vendor/libgit2/include/git2/diff.h +22 -32
  22. data/vendor/libgit2/include/git2/errors.h +0 -1
  23. data/vendor/libgit2/include/git2/ignore.h +2 -2
  24. data/vendor/libgit2/include/git2/merge.h +8 -10
  25. data/vendor/libgit2/include/git2/proxy.h +5 -9
  26. data/vendor/libgit2/include/git2/rebase.h +4 -7
  27. data/vendor/libgit2/include/git2/refs.h +1 -1
  28. data/vendor/libgit2/include/git2/refspec.h +0 -17
  29. data/vendor/libgit2/include/git2/remote.h +10 -12
  30. data/vendor/libgit2/include/git2/repository.h +5 -7
  31. data/vendor/libgit2/include/git2/revert.h +3 -5
  32. data/vendor/libgit2/include/git2/stash.h +8 -11
  33. data/vendor/libgit2/include/git2/status.h +3 -7
  34. data/vendor/libgit2/include/git2/submodule.h +7 -8
  35. data/vendor/libgit2/include/git2/sys/index.h +0 -3
  36. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  37. data/vendor/libgit2/include/git2/sys/merge.h +1 -6
  38. data/vendor/libgit2/include/git2/transaction.h +0 -1
  39. data/vendor/libgit2/include/git2/types.h +5 -8
  40. data/vendor/libgit2/include/git2/version.h +2 -2
  41. data/vendor/libgit2/include/git2/worktree.h +11 -46
  42. data/vendor/libgit2/src/CMakeLists.txt +28 -91
  43. data/vendor/libgit2/src/annotated_commit.c +4 -4
  44. data/vendor/libgit2/src/apply.c +6 -5
  45. data/vendor/libgit2/src/attr.c +4 -4
  46. data/vendor/libgit2/src/attr_file.c +5 -5
  47. data/vendor/libgit2/src/attrcache.c +2 -2
  48. data/vendor/libgit2/src/blame.c +4 -11
  49. data/vendor/libgit2/src/blame.h +0 -1
  50. data/vendor/libgit2/src/blame_git.c +5 -8
  51. data/vendor/libgit2/src/blob.c +5 -5
  52. data/vendor/libgit2/src/branch.c +20 -20
  53. data/vendor/libgit2/src/buffer.c +4 -9
  54. data/vendor/libgit2/src/buffer.h +1 -1
  55. data/vendor/libgit2/src/checkout.c +24 -33
  56. data/vendor/libgit2/src/cherrypick.c +3 -3
  57. data/vendor/libgit2/src/clone.c +13 -13
  58. data/vendor/libgit2/src/commit.c +5 -18
  59. data/vendor/libgit2/src/commit_list.c +9 -3
  60. data/vendor/libgit2/src/common.h +1 -3
  61. data/vendor/libgit2/src/config.c +15 -6
  62. data/vendor/libgit2/src/config_file.c +249 -193
  63. data/vendor/libgit2/src/config_parse.c +66 -89
  64. data/vendor/libgit2/src/config_parse.h +2 -2
  65. data/vendor/libgit2/src/crlf.c +3 -9
  66. data/vendor/libgit2/src/diff.c +2 -2
  67. data/vendor/libgit2/src/diff_driver.c +3 -3
  68. data/vendor/libgit2/src/diff_file.c +3 -3
  69. data/vendor/libgit2/src/diff_generate.c +3 -4
  70. data/vendor/libgit2/src/diff_print.c +8 -8
  71. data/vendor/libgit2/src/diff_tform.c +4 -2
  72. data/vendor/libgit2/src/diff_xdiff.c +0 -12
  73. data/vendor/libgit2/src/features.h.in +0 -2
  74. data/vendor/libgit2/src/fetch.c +2 -2
  75. data/vendor/libgit2/src/fetchhead.c +5 -5
  76. data/vendor/libgit2/src/filebuf.c +4 -4
  77. data/vendor/libgit2/src/fileops.c +10 -10
  78. data/vendor/libgit2/src/filter.c +9 -3
  79. data/vendor/libgit2/src/global.c +12 -17
  80. data/vendor/libgit2/src/hash.h +0 -2
  81. data/vendor/libgit2/src/ignore.c +5 -5
  82. data/vendor/libgit2/src/index.c +40 -80
  83. data/vendor/libgit2/src/index.h +0 -10
  84. data/vendor/libgit2/src/indexer.c +9 -9
  85. data/vendor/libgit2/src/iterator.c +8 -8
  86. data/vendor/libgit2/src/khash.h +1 -3
  87. data/vendor/libgit2/src/merge.c +7 -7
  88. data/vendor/libgit2/src/netops.c +5 -5
  89. data/vendor/libgit2/src/notes.c +2 -2
  90. data/vendor/libgit2/src/odb.c +9 -9
  91. data/vendor/libgit2/src/odb_loose.c +22 -18
  92. data/vendor/libgit2/src/odb_pack.c +3 -3
  93. data/vendor/libgit2/src/pack-objects.c +3 -3
  94. data/vendor/libgit2/src/pack.c +5 -5
  95. data/vendor/libgit2/src/pack.h +1 -1
  96. data/vendor/libgit2/src/parse.c +7 -4
  97. data/vendor/libgit2/src/patch.c +1 -1
  98. data/vendor/libgit2/src/patch_generate.c +2 -2
  99. data/vendor/libgit2/src/patch_parse.c +4 -24
  100. data/vendor/libgit2/src/path.c +140 -39
  101. data/vendor/libgit2/src/path.h +84 -2
  102. data/vendor/libgit2/src/pathspec.c +1 -1
  103. data/vendor/libgit2/src/push.c +2 -2
  104. data/vendor/libgit2/src/rebase.c +23 -20
  105. data/vendor/libgit2/src/refdb_fs.c +34 -65
  106. data/vendor/libgit2/src/refs.c +16 -13
  107. data/vendor/libgit2/src/refspec.c +5 -30
  108. data/vendor/libgit2/src/refspec.h +1 -1
  109. data/vendor/libgit2/src/remote.c +43 -43
  110. data/vendor/libgit2/src/repository.c +56 -56
  111. data/vendor/libgit2/src/reset.c +1 -1
  112. data/vendor/libgit2/src/revert.c +3 -3
  113. data/vendor/libgit2/src/revparse.c +7 -6
  114. data/vendor/libgit2/src/revwalk.c +20 -48
  115. data/vendor/libgit2/src/revwalk.h +1 -2
  116. data/vendor/libgit2/src/settings.c +1 -25
  117. data/vendor/libgit2/src/signature.c +4 -2
  118. data/vendor/libgit2/src/stash.c +34 -80
  119. data/vendor/libgit2/src/status.c +1 -1
  120. data/vendor/libgit2/src/streams/curl.c +1 -1
  121. data/vendor/libgit2/src/streams/openssl.c +34 -132
  122. data/vendor/libgit2/src/streams/openssl.h +107 -0
  123. data/vendor/libgit2/src/streams/tls.c +0 -3
  124. data/vendor/libgit2/src/submodule.c +83 -118
  125. data/vendor/libgit2/src/sysdir.c +4 -4
  126. data/vendor/libgit2/src/tag.c +12 -12
  127. data/vendor/libgit2/src/trace.h +1 -1
  128. data/vendor/libgit2/src/trailer.c +6 -6
  129. data/vendor/libgit2/src/transport.c +2 -2
  130. data/vendor/libgit2/src/transports/auth.c +1 -1
  131. data/vendor/libgit2/src/transports/auth_negotiate.c +2 -2
  132. data/vendor/libgit2/src/transports/git.c +1 -1
  133. data/vendor/libgit2/src/transports/http.c +15 -12
  134. data/vendor/libgit2/src/transports/local.c +7 -7
  135. data/vendor/libgit2/src/transports/smart.c +15 -20
  136. data/vendor/libgit2/src/transports/smart.h +5 -5
  137. data/vendor/libgit2/src/transports/smart_pkt.c +131 -123
  138. data/vendor/libgit2/src/transports/smart_protocol.c +38 -48
  139. data/vendor/libgit2/src/transports/ssh.c +1 -1
  140. data/vendor/libgit2/src/transports/winhttp.c +26 -21
  141. data/vendor/libgit2/src/tree-cache.c +2 -2
  142. data/vendor/libgit2/src/tree.c +69 -23
  143. data/vendor/libgit2/src/tree.h +12 -0
  144. data/vendor/libgit2/src/util.c +99 -52
  145. data/vendor/libgit2/src/util.h +138 -14
  146. data/vendor/libgit2/src/vector.c +13 -8
  147. data/vendor/libgit2/src/win32/findfile.c +2 -2
  148. data/vendor/libgit2/src/win32/posix_w32.c +1 -1
  149. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -94
  150. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +75 -28
  151. data/vendor/libgit2/src/worktree.c +44 -65
  152. data/vendor/libgit2/src/worktree.h +0 -2
  153. data/vendor/libgit2/src/xdiff/xdiffi.c +1 -3
  154. metadata +5 -17
  155. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +0 -93
  156. data/vendor/libgit2/include/git2/mailmap.h +0 -115
  157. data/vendor/libgit2/include/git2/sys/alloc.h +0 -101
  158. data/vendor/libgit2/include/git2/sys/path.h +0 -55
  159. data/vendor/libgit2/src/alloc.c +0 -47
  160. data/vendor/libgit2/src/alloc.h +0 -40
  161. data/vendor/libgit2/src/hash/hash_mbedtls.c +0 -38
  162. data/vendor/libgit2/src/hash/hash_mbedtls.h +0 -20
  163. data/vendor/libgit2/src/mailmap.c +0 -485
  164. data/vendor/libgit2/src/mailmap.h +0 -35
  165. data/vendor/libgit2/src/stdalloc.c +0 -120
  166. data/vendor/libgit2/src/stdalloc.h +0 -17
  167. data/vendor/libgit2/src/streams/mbedtls.c +0 -463
  168. data/vendor/libgit2/src/streams/mbedtls.h +0 -20
@@ -210,7 +210,7 @@ static int packfile_load__cb(void *data, git_buf *path)
210
210
  for (i = 0; i < backend->packs.length; ++i) {
211
211
  struct git_pack_file *p = git_vector_get(&backend->packs, i);
212
212
 
213
- if (memcmp(p->pack_name, path_str, cmp_len) == 0)
213
+ if (strncmp(p->pack_name, path_str, cmp_len) == 0)
214
214
  return 0;
215
215
  }
216
216
 
@@ -346,7 +346,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
346
346
  /* reload all packs */
347
347
  error = git_path_direach(&path, 0, packfile_load__cb, backend);
348
348
 
349
- git_buf_dispose(&path);
349
+ git_buf_free(&path);
350
350
  git_vector_sort(&backend->packs);
351
351
 
352
352
  return error;
@@ -635,7 +635,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
635
635
 
636
636
  *backend_out = (git_odb_backend *)backend;
637
637
 
638
- git_buf_dispose(&path);
638
+ git_buf_free(&path);
639
639
 
640
640
  return error;
641
641
  }
@@ -1095,7 +1095,7 @@ on_error:
1095
1095
  git__free(array[i].data);
1096
1096
  }
1097
1097
  git__free(array);
1098
- git_buf_dispose(&zbuf);
1098
+ git_buf_free(&zbuf);
1099
1099
 
1100
1100
  return error;
1101
1101
  }
@@ -1463,7 +1463,7 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
1463
1463
  error = git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, &context);
1464
1464
 
1465
1465
  git_tree_free(tree);
1466
- git_buf_dispose(&context.buf);
1466
+ git_buf_free(&context.buf);
1467
1467
  return error;
1468
1468
  }
1469
1469
 
@@ -1666,7 +1666,7 @@ int insert_tree(git_packbuilder *pb, git_tree *tree)
1666
1666
 
1667
1667
  break;
1668
1668
  case GIT_OBJ_BLOB:
1669
- if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
1669
+ if ((error = retrieve_object(&obj, pb, entry_id)) < 0)
1670
1670
  return error;
1671
1671
  if (obj->uninteresting)
1672
1672
  continue;
@@ -326,19 +326,19 @@ static int pack_index_open(struct git_pack_file *p)
326
326
  git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
327
327
  git_buf_puts(&idx_name, ".idx");
328
328
  if (git_buf_oom(&idx_name)) {
329
- git_buf_dispose(&idx_name);
329
+ git_buf_free(&idx_name);
330
330
  return -1;
331
331
  }
332
332
 
333
333
  if ((error = git_mutex_lock(&p->lock)) < 0) {
334
- git_buf_dispose(&idx_name);
334
+ git_buf_free(&idx_name);
335
335
  return error;
336
336
  }
337
337
 
338
338
  if (p->index_version == -1)
339
339
  error = pack_index_check(idx_name.ptr, p);
340
340
 
341
- git_buf_dispose(&idx_name);
341
+ git_buf_free(&idx_name);
342
342
 
343
343
  git_mutex_unlock(&p->lock);
344
344
 
@@ -499,7 +499,7 @@ int git_packfile_resolve_header(
499
499
  if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0)
500
500
  return error;
501
501
  error = git_delta_read_header_fromstream(&base_size, size_p, &stream);
502
- git_packfile_stream_dispose(&stream);
502
+ git_packfile_stream_free(&stream);
503
503
  if (error < 0)
504
504
  return error;
505
505
  } else {
@@ -840,7 +840,7 @@ ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t
840
840
 
841
841
  }
842
842
 
843
- void git_packfile_stream_dispose(git_packfile_stream *obj)
843
+ void git_packfile_stream_free(git_packfile_stream *obj)
844
844
  {
845
845
  inflateEnd(&obj->zstream);
846
846
  }
@@ -144,7 +144,7 @@ int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, git_off_t *obj
144
144
 
145
145
  int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, git_off_t curpos);
146
146
  ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
147
- void git_packfile_stream_dispose(git_packfile_stream *obj);
147
+ void git_packfile_stream_free(git_packfile_stream *obj);
148
148
 
149
149
  git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
150
150
  git_off_t *curpos, git_otype type,
@@ -8,12 +8,14 @@
8
8
 
9
9
  int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len)
10
10
  {
11
- if (content_len)
11
+ if (content && content_len) {
12
12
  ctx->content = content;
13
- else
14
- ctx->content = NULL;
13
+ ctx->content_len = content_len;
14
+ } else {
15
+ ctx->content = "";
16
+ ctx->content_len = 0;
17
+ }
15
18
 
16
- ctx->content_len = content_len;
17
19
  ctx->remain = ctx->content;
18
20
  ctx->remain_len = ctx->content_len;
19
21
  ctx->line = ctx->remain;
@@ -26,6 +28,7 @@ int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_l
26
28
  void git_parse_ctx_clear(git_parse_ctx *ctx)
27
29
  {
28
30
  memset(ctx, 0, sizeof(*ctx));
31
+ ctx->content = "";
29
32
  }
30
33
 
31
34
  void git_parse_advance_line(git_parse_ctx *ctx)
@@ -84,7 +84,7 @@ size_t git_patch_size(
84
84
  else
85
85
  out += git_buf_len(&file_header);
86
86
 
87
- git_buf_dispose(&file_header);
87
+ git_buf_free(&file_header);
88
88
  }
89
89
 
90
90
  return out;
@@ -314,8 +314,8 @@ static int create_binary(
314
314
  }
315
315
 
316
316
  done:
317
- git_buf_dispose(&deflate);
318
- git_buf_dispose(&delta);
317
+ git_buf_free(&deflate);
318
+ git_buf_free(&delta);
319
319
 
320
320
  return error;
321
321
  }
@@ -98,7 +98,7 @@ static int parse_header_git_oldpath(
98
98
  patch->old_path = git_buf_detach(&old_path);
99
99
 
100
100
  out:
101
- git_buf_dispose(&old_path);
101
+ git_buf_free(&old_path);
102
102
  return error;
103
103
  }
104
104
 
@@ -114,7 +114,7 @@ static int parse_header_git_newpath(
114
114
  patch->new_path = git_buf_detach(&new_path);
115
115
 
116
116
  out:
117
- git_buf_dispose(&new_path);
117
+ git_buf_free(&new_path);
118
118
  return error;
119
119
  }
120
120
 
@@ -458,26 +458,6 @@ done:
458
458
  return error;
459
459
  }
460
460
 
461
- static int parse_number(git_off_t *out, git_patch_parse_ctx *ctx)
462
- {
463
- const char *end;
464
- int64_t num;
465
-
466
- if (!git__isdigit(ctx->parse_ctx.line[0]))
467
- return -1;
468
-
469
- if (git__strntol64(&num, ctx->parse_ctx.line, ctx->parse_ctx.line_len, &end, 10) < 0)
470
- return -1;
471
-
472
- if (num < 0)
473
- return -1;
474
-
475
- *out = num;
476
- git_parse_advance_chars(&ctx->parse_ctx, (end - ctx->parse_ctx.line));
477
-
478
- return 0;
479
- }
480
-
481
461
  static int parse_int(int *out, git_patch_parse_ctx *ctx)
482
462
  {
483
463
  git_off_t num;
@@ -777,8 +757,8 @@ static int parse_patch_binary_side(
777
757
  binary->data = git_buf_detach(&decoded);
778
758
 
779
759
  done:
780
- git_buf_dispose(&base85);
781
- git_buf_dispose(&decoded);
760
+ git_buf_free(&base85);
761
+ git_buf_free(&decoded);
782
762
  return error;
783
763
  }
784
764
 
@@ -14,6 +14,7 @@
14
14
  #include "win32/w32_buffer.h"
15
15
  #include "win32/w32_util.h"
16
16
  #include "win32/version.h"
17
+ #include <AclAPI.h>
17
18
  #else
18
19
  #include <dirent.h>
19
20
  #endif
@@ -207,7 +208,7 @@ char *git_path_dirname(const char *path)
207
208
 
208
209
  git_path_dirname_r(&buf, path);
209
210
  dirname = git_buf_detach(&buf);
210
- git_buf_dispose(&buf); /* avoid memleak if error occurs */
211
+ git_buf_free(&buf); /* avoid memleak if error occurs */
211
212
 
212
213
  return dirname;
213
214
  }
@@ -219,7 +220,7 @@ char *git_path_basename(const char *path)
219
220
 
220
221
  git_path_basename_r(&buf, path);
221
222
  basename = git_buf_detach(&buf);
222
- git_buf_dispose(&buf); /* avoid memleak if error occurs */
223
+ git_buf_free(&buf); /* avoid memleak if error occurs */
223
224
 
224
225
  return basename;
225
226
  }
@@ -642,7 +643,7 @@ bool git_path_is_empty_dir(const char *path)
642
643
  else
643
644
  error = git_path_direach(&dir, 0, path_found_entry, NULL);
644
645
 
645
- git_buf_dispose(&dir);
646
+ git_buf_free(&dir);
646
647
 
647
648
  return !error;
648
649
  }
@@ -956,7 +957,7 @@ void git_path_iconv_clear(git_path_iconv_t *ic)
956
957
  if (ic) {
957
958
  if (ic->map != (iconv_t)-1)
958
959
  iconv_close(ic->map);
959
- git_buf_dispose(&ic->buf);
960
+ git_buf_free(&ic->buf);
960
961
  }
961
962
  }
962
963
 
@@ -1060,7 +1061,7 @@ bool git_path_does_fs_decompose_unicode(const char *root)
1060
1061
  (void)p_unlink(path.ptr);
1061
1062
 
1062
1063
  done:
1063
- git_buf_dispose(&path);
1064
+ git_buf_free(&path);
1064
1065
  return found_decomposed;
1065
1066
  }
1066
1067
 
@@ -1308,7 +1309,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
1308
1309
  if (diriter == NULL)
1309
1310
  return;
1310
1311
 
1311
- git_buf_dispose(&diriter->path_utf8);
1312
+ git_buf_free(&diriter->path_utf8);
1312
1313
 
1313
1314
  if (diriter->handle != INVALID_HANDLE_VALUE) {
1314
1315
  FindClose(diriter->handle);
@@ -1338,7 +1339,7 @@ int git_path_diriter_init(
1338
1339
  }
1339
1340
 
1340
1341
  if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
1341
- git_buf_dispose(&diriter->path);
1342
+ git_buf_free(&diriter->path);
1342
1343
 
1343
1344
  giterr_set(GITERR_OS, "failed to open directory '%s'", path);
1344
1345
  return -1;
@@ -1448,7 +1449,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
1448
1449
  git_path_iconv_clear(&diriter->ic);
1449
1450
  #endif
1450
1451
 
1451
- git_buf_dispose(&diriter->path);
1452
+ git_buf_free(&diriter->path);
1452
1453
  }
1453
1454
 
1454
1455
  #endif
@@ -1766,14 +1767,14 @@ static bool verify_component(
1766
1767
  if (flags & GIT_PATH_REJECT_DOT_GIT_HFS) {
1767
1768
  if (!verify_dotgit_hfs(component, len))
1768
1769
  return false;
1769
- if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
1770
+ if (S_ISLNK(mode) && git_path_is_hfs_dotgit_modules(component, len))
1770
1771
  return false;
1771
1772
  }
1772
1773
 
1773
1774
  if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) {
1774
1775
  if (!verify_dotgit_ntfs(repo, component, len))
1775
1776
  return false;
1776
- if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
1777
+ if (S_ISLNK(mode) && git_path_is_ntfs_dotgit_modules(component, len))
1777
1778
  return false;
1778
1779
  }
1779
1780
 
@@ -1872,40 +1873,140 @@ int git_path_normalize_slashes(git_buf *out, const char *path)
1872
1873
  return 0;
1873
1874
  }
1874
1875
 
1875
- static const struct {
1876
- const char *file;
1877
- const char *hash;
1878
- size_t filelen;
1879
- } gitfiles[] = {
1880
- { "gitignore", "gi250a", CONST_STRLEN("gitignore") },
1881
- { "gitmodules", "gi7eba", CONST_STRLEN("gitmodules") },
1882
- { "gitattributes", "gi7d29", CONST_STRLEN("gitattributes") }
1883
- };
1876
+ static int verify_dotgit_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix)
1877
+ {
1878
+ if (!verify_dotgit_ntfs_generic(name, len, dotgit_name, dotgit_len, shortname_pfix))
1879
+ return false;
1880
+
1881
+ return verify_dotgit_hfs_generic(name, len, dotgit_name, dotgit_len);
1882
+ }
1883
+
1884
+ int git_path_is_ntfs_dotgit_modules(const char *name, size_t len)
1885
+ {
1886
+ return !verify_dotgit_ntfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"), "gi7eba");
1887
+ }
1888
+
1889
+ int git_path_is_hfs_dotgit_modules(const char *name, size_t len)
1890
+ {
1891
+ return !verify_dotgit_hfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"));
1892
+ }
1893
+
1894
+ int git_path_is_dotgit_modules(const char *name, size_t len)
1895
+ {
1896
+ if (git_path_is_hfs_dotgit_modules(name, len))
1897
+ return 1;
1898
+
1899
+ return git_path_is_ntfs_dotgit_modules(name, len);
1900
+ }
1884
1901
 
1885
- extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs)
1902
+ int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len)
1886
1903
  {
1887
- const char *file, *hash;
1888
- size_t filelen;
1904
+ return !verify_dotgit_ntfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"), "gi250a");
1905
+ }
1906
+
1907
+ int git_path_is_hfs_dotgit_ignore(const char *name, size_t len)
1908
+ {
1909
+ return !verify_dotgit_hfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"));
1910
+ }
1911
+
1912
+ int git_path_is_dotgit_ignore(const char *name, size_t len)
1913
+ {
1914
+ if (git_path_is_hfs_dotgit_ignore(name, len))
1915
+ return 1;
1916
+
1917
+ return git_path_is_ntfs_dotgit_ignore(name, len);
1918
+ }
1919
+
1920
+ int git_path_is_hfs_dotgit_attributes(const char *name, size_t len)
1921
+ {
1922
+ return !verify_dotgit_hfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"));
1923
+ }
1924
+
1925
+ int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len)
1926
+ {
1927
+ return !verify_dotgit_ntfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"), "gi7d29");
1928
+ }
1889
1929
 
1890
- if (gitfile < 0 && gitfile >= ARRAY_SIZE(gitfiles)) {
1891
- giterr_set(GITERR_OS, "invalid gitfile for path validation");
1930
+ int git_path_is_dotgit_attributes(const char *name, size_t len)
1931
+ {
1932
+ if (git_path_is_hfs_dotgit_attributes(name, len))
1933
+ return 1;
1934
+
1935
+ return git_path_is_ntfs_dotgit_attributes(name, len);
1936
+ }
1937
+
1938
+ int git_path_validate_system_file_ownership(const char *path)
1939
+ {
1940
+ #ifndef GIT_WIN32
1941
+ GIT_UNUSED(path);
1942
+ return GIT_OK;
1943
+ #else
1944
+ git_win32_path buf;
1945
+ PSID owner_sid;
1946
+ PSECURITY_DESCRIPTOR descriptor = NULL;
1947
+ HANDLE token;
1948
+ TOKEN_USER *info = NULL;
1949
+ DWORD err, len;
1950
+ int ret;
1951
+
1952
+ if (git_win32_path_from_utf8(buf, path) < 0)
1892
1953
  return -1;
1954
+
1955
+ err = GetNamedSecurityInfoW(buf, SE_FILE_OBJECT,
1956
+ OWNER_SECURITY_INFORMATION |
1957
+ DACL_SECURITY_INFORMATION,
1958
+ &owner_sid, NULL, NULL, NULL, &descriptor);
1959
+
1960
+ if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) {
1961
+ ret = GIT_ENOTFOUND;
1962
+ goto cleanup;
1893
1963
  }
1894
1964
 
1895
- file = gitfiles[gitfile].file;
1896
- filelen = gitfiles[gitfile].filelen;
1897
- hash = gitfiles[gitfile].hash;
1898
-
1899
- switch (fs) {
1900
- case GIT_PATH_FS_GENERIC:
1901
- return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) ||
1902
- !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
1903
- case GIT_PATH_FS_NTFS:
1904
- return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash);
1905
- case GIT_PATH_FS_HFS:
1906
- return !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
1907
- default:
1908
- giterr_set(GITERR_OS, "invalid filesystem for path validation");
1909
- return -1;
1965
+ if (err != ERROR_SUCCESS) {
1966
+ giterr_set(GITERR_OS, "failed to get security information");
1967
+ ret = GIT_ERROR;
1968
+ goto cleanup;
1969
+ }
1970
+
1971
+ if (!IsValidSid(owner_sid)) {
1972
+ giterr_set(GITERR_INVALID, "programdata configuration file owner is unknown");
1973
+ ret = GIT_ERROR;
1974
+ goto cleanup;
1910
1975
  }
1976
+
1977
+ if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) ||
1978
+ IsWellKnownSid(owner_sid, WinLocalSystemSid)) {
1979
+ ret = GIT_OK;
1980
+ goto cleanup;
1981
+ }
1982
+
1983
+ /* Obtain current user's SID */
1984
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) &&
1985
+ !GetTokenInformation(token, TokenUser, NULL, 0, &len)) {
1986
+ info = git__malloc(len);
1987
+ GITERR_CHECK_ALLOC(info);
1988
+ if (!GetTokenInformation(token, TokenUser, info, len, &len)) {
1989
+ git__free(info);
1990
+ info = NULL;
1991
+ }
1992
+ }
1993
+
1994
+ /*
1995
+ * If the file is owned by the same account that is running the current
1996
+ * process, it's okay to read from that file.
1997
+ */
1998
+ if (info && EqualSid(owner_sid, info->User.Sid))
1999
+ ret = GIT_OK;
2000
+ else {
2001
+ giterr_set(GITERR_INVALID, "programdata configuration file owner is not valid");
2002
+ ret = GIT_ERROR;
2003
+ }
2004
+ free(info);
2005
+
2006
+ cleanup:
2007
+ if (descriptor)
2008
+ LocalFree(descriptor);
2009
+
2010
+ return ret;
2011
+ #endif
1911
2012
  }