rugged 0.24.0 → 0.24.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +20 -9
  4. data/vendor/libgit2/deps/http-parser/http_parser.c +5 -2
  5. data/vendor/libgit2/include/git2/checkout.h +7 -0
  6. data/vendor/libgit2/include/git2/common.h +16 -1
  7. data/vendor/libgit2/include/git2/version.h +2 -2
  8. data/vendor/libgit2/src/array.h +40 -0
  9. data/vendor/libgit2/src/blame.c +8 -3
  10. data/vendor/libgit2/src/blame_git.c +20 -9
  11. data/vendor/libgit2/src/checkout.c +13 -5
  12. data/vendor/libgit2/src/commit.c +5 -4
  13. data/vendor/libgit2/src/common.h +1 -1
  14. data/vendor/libgit2/src/config_cache.c +2 -1
  15. data/vendor/libgit2/src/config_file.c +14 -20
  16. data/vendor/libgit2/src/delta-apply.c +36 -5
  17. data/vendor/libgit2/src/delta-apply.h +12 -0
  18. data/vendor/libgit2/src/describe.c +2 -1
  19. data/vendor/libgit2/src/diff_tform.c +5 -3
  20. data/vendor/libgit2/src/filebuf.c +6 -1
  21. data/vendor/libgit2/src/global.c +28 -8
  22. data/vendor/libgit2/src/global.h +1 -0
  23. data/vendor/libgit2/src/ignore.c +56 -19
  24. data/vendor/libgit2/src/index.c +27 -8
  25. data/vendor/libgit2/src/indexer.c +11 -7
  26. data/vendor/libgit2/src/iterator.c +2 -2
  27. data/vendor/libgit2/src/merge.c +1 -0
  28. data/vendor/libgit2/src/mwindow.c +20 -21
  29. data/vendor/libgit2/src/mwindow.h +1 -2
  30. data/vendor/libgit2/src/object.c +3 -6
  31. data/vendor/libgit2/src/odb.c +11 -15
  32. data/vendor/libgit2/src/odb.h +2 -1
  33. data/vendor/libgit2/src/odb_loose.c +13 -9
  34. data/vendor/libgit2/src/odb_pack.c +5 -6
  35. data/vendor/libgit2/src/oid.h +9 -0
  36. data/vendor/libgit2/src/openssl_stream.c +60 -27
  37. data/vendor/libgit2/src/openssl_stream.h +106 -0
  38. data/vendor/libgit2/src/pack-objects.c +4 -2
  39. data/vendor/libgit2/src/pack.c +10 -14
  40. data/vendor/libgit2/src/posix.c +7 -0
  41. data/vendor/libgit2/src/posix.h +1 -0
  42. data/vendor/libgit2/src/push.c +6 -6
  43. data/vendor/libgit2/src/refdb_fs.c +1 -0
  44. data/vendor/libgit2/src/refs.c +3 -0
  45. data/vendor/libgit2/src/refspec.c +4 -2
  46. data/vendor/libgit2/src/remote.c +15 -5
  47. data/vendor/libgit2/src/repository.c +29 -21
  48. data/vendor/libgit2/src/settings.c +23 -1
  49. data/vendor/libgit2/src/stransport_stream.c +15 -9
  50. data/vendor/libgit2/src/submodule.c +3 -2
  51. data/vendor/libgit2/src/sysdir.c +41 -47
  52. data/vendor/libgit2/src/sysdir.h +0 -5
  53. data/vendor/libgit2/src/tag.c +8 -2
  54. data/vendor/libgit2/src/thread-utils.h +5 -51
  55. data/vendor/libgit2/src/transport.c +2 -0
  56. data/vendor/libgit2/src/transports/http.c +2 -1
  57. data/vendor/libgit2/src/transports/smart_pkt.c +1 -0
  58. data/vendor/libgit2/src/transports/smart_protocol.c +72 -17
  59. data/vendor/libgit2/src/transports/ssh.c +32 -17
  60. data/vendor/libgit2/src/tree.c +83 -100
  61. data/vendor/libgit2/src/tree.h +4 -5
  62. data/vendor/libgit2/src/unix/map.c +5 -0
  63. data/vendor/libgit2/src/unix/pthread.h +54 -0
  64. data/vendor/libgit2/src/util.c +3 -3
  65. data/vendor/libgit2/src/win32/map.c +24 -5
  66. data/vendor/libgit2/src/win32/precompiled.h +1 -1
  67. data/vendor/libgit2/src/win32/{pthread.c → thread.c} +50 -80
  68. data/vendor/libgit2/src/win32/thread.h +62 -0
  69. data/vendor/libgit2/src/xdiff/xprepare.c +2 -1
  70. metadata +384 -394
  71. data/vendor/libgit2/src/win32/pthread.h +0 -92
@@ -458,7 +458,7 @@ static int tree_iterator__set_next(tree_iterator *ti, tree_iterator_frame *tf)
458
458
  /* try to load trees for items in [current,next) range */
459
459
  if (!error && git_tree_entry__is_tree(te))
460
460
  error = git_tree_lookup(
461
- &tf->entries[tf->next]->tree, ti->base.repo, &te->oid);
461
+ &tf->entries[tf->next]->tree, ti->base.repo, te->oid);
462
462
  }
463
463
 
464
464
  if (tf->next > tf->current + 1)
@@ -603,7 +603,7 @@ static int tree_iterator__update_entry(tree_iterator *ti)
603
603
  te = tf->entries[tf->current]->te;
604
604
 
605
605
  ti->entry.mode = te->attr;
606
- git_oid_cpy(&ti->entry.id, &te->oid);
606
+ git_oid_cpy(&ti->entry.id, te->oid);
607
607
 
608
608
  ti->entry.path = tree_iterator__current_filename(ti, te);
609
609
  GITERR_CHECK_ALLOC(ti->entry.path);
@@ -2730,6 +2730,7 @@ static int merge_check_workdir(size_t *conflicts, git_repository *repo, git_inde
2730
2730
  opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
2731
2731
  opts.pathspec.count = merged_paths->length;
2732
2732
  opts.pathspec.strings = (char **)merged_paths->contents;
2733
+ opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL;
2733
2734
 
2734
2735
  if ((error = git_diff_index_to_workdir(&wd_diff_list, repo, NULL, &opts)) < 0)
2735
2736
  goto done;
@@ -33,25 +33,20 @@ static git_mwindow_ctl mem_ctl;
33
33
  /* Global list of mwindow files, to open packs once across repos */
34
34
  git_strmap *git__pack_cache = NULL;
35
35
 
36
- /**
37
- * Run under mwindow lock
38
- */
39
- int git_mwindow_files_init(void)
36
+ static void git_mwindow_files_free(void)
40
37
  {
41
- if (git__pack_cache)
42
- return 0;
43
-
44
- git__on_shutdown(git_mwindow_files_free);
38
+ git_strmap *tmp = git__pack_cache;
45
39
 
46
- return git_strmap_alloc(&git__pack_cache);
40
+ git__pack_cache = NULL;
41
+ git_strmap_free(tmp);
47
42
  }
48
43
 
49
- void git_mwindow_files_free(void)
44
+ int git_mwindow_global_init(void)
50
45
  {
51
- git_strmap *tmp = git__pack_cache;
46
+ assert(!git__pack_cache);
52
47
 
53
- git__pack_cache = NULL;
54
- git_strmap_free(tmp);
48
+ git__on_shutdown(git_mwindow_files_free);
49
+ return git_strmap_alloc(&git__pack_cache);
55
50
  }
56
51
 
57
52
  int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
@@ -69,12 +64,6 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
69
64
  return -1;
70
65
  }
71
66
 
72
- if (git_mwindow_files_init() < 0) {
73
- git_mutex_unlock(&git__mwindow_mutex);
74
- git__free(packname);
75
- return -1;
76
- }
77
-
78
67
  pos = git_strmap_lookup_index(git__pack_cache, packname);
79
68
  git__free(packname);
80
69
 
@@ -296,8 +285,18 @@ static git_mwindow *new_window(
296
285
  */
297
286
 
298
287
  if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) {
299
- git__free(w);
300
- return NULL;
288
+ /*
289
+ * The first error might be down to memory fragmentation even if
290
+ * we're below our soft limits, so free up what we can and try again.
291
+ */
292
+
293
+ while (git_mwindow_close_lru(mwf) == 0)
294
+ /* nop */;
295
+
296
+ if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) {
297
+ git__free(w);
298
+ return NULL;
299
+ }
301
300
  }
302
301
 
303
302
  ctl->mmap_calls++;
@@ -43,8 +43,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf);
43
43
  void git_mwindow_file_deregister(git_mwindow_file *mwf);
44
44
  void git_mwindow_close(git_mwindow **w_cursor);
45
45
 
46
- int git_mwindow_files_init(void);
47
- void git_mwindow_files_free(void);
46
+ extern int git_mwindow_global_init(void);
48
47
 
49
48
  struct git_pack_file; /* just declaration to avoid cyclical includes */
50
49
  int git_mwindow_get_pack(struct git_pack_file **out, const char *path);
@@ -12,6 +12,7 @@
12
12
  #include "commit.h"
13
13
  #include "tree.h"
14
14
  #include "blob.h"
15
+ #include "oid.h"
15
16
  #include "tag.h"
16
17
 
17
18
  bool git_object__strict_input_validation = true;
@@ -166,13 +167,9 @@ int git_object_lookup_prefix(
166
167
  error = git_odb_read(&odb_obj, odb, id);
167
168
  }
168
169
  } else {
169
- git_oid short_oid;
170
+ git_oid short_oid = {{ 0 }};
170
171
 
171
- /* We copy the first len*4 bits from id and fill the remaining with 0s */
172
- memcpy(short_oid.id, id->id, (len + 1) / 2);
173
- if (len % 2)
174
- short_oid.id[len / 2] &= 0xF0;
175
- memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2);
172
+ git_oid__cpy_prefix(&short_oid, id, len);
176
173
 
177
174
  /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
178
175
  * 2 options :
@@ -725,7 +725,8 @@ int git_odb_exists_prefix(
725
725
  git_oid_cpy(out, short_id);
726
726
  return 0;
727
727
  } else {
728
- return git_odb__error_notfound("no match for id prefix", short_id);
728
+ return git_odb__error_notfound(
729
+ "no match for id prefix", short_id, len);
729
730
  }
730
731
  }
731
732
 
@@ -740,7 +741,7 @@ int git_odb_exists_prefix(
740
741
  error = odb_exists_prefix_1(out, db, &key, len, true);
741
742
 
742
743
  if (error == GIT_ENOTFOUND)
743
- return git_odb__error_notfound("no match for id prefix", &key);
744
+ return git_odb__error_notfound("no match for id prefix", &key, len);
744
745
 
745
746
  return error;
746
747
  }
@@ -802,19 +803,12 @@ int git_odb__read_header_or_object(
802
803
  return 0;
803
804
  }
804
805
 
805
- static git_oid empty_blob = {{ 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b,
806
- 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }};
807
806
  static git_oid empty_tree = {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
808
807
  0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }};
809
808
 
810
809
  static int hardcoded_objects(git_rawobj *raw, const git_oid *id)
811
810
  {
812
- if (!git_oid_cmp(id, &empty_blob)) {
813
- raw->type = GIT_OBJ_BLOB;
814
- raw->len = 0;
815
- raw->data = git__calloc(1, sizeof(uint8_t));
816
- return 0;
817
- } else if (!git_oid_cmp(id, &empty_tree)) {
811
+ if (!git_oid_cmp(id, &empty_tree)) {
818
812
  raw->type = GIT_OBJ_TREE;
819
813
  raw->len = 0;
820
814
  raw->data = git__calloc(1, sizeof(uint8_t));
@@ -881,7 +875,7 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
881
875
  error = odb_read_1(out, db, id, true);
882
876
 
883
877
  if (error == GIT_ENOTFOUND)
884
- return git_odb__error_notfound("no match for id", id);
878
+ return git_odb__error_notfound("no match for id", id, GIT_OID_HEXSZ);
885
879
 
886
880
  return error;
887
881
  }
@@ -967,7 +961,7 @@ int git_odb_read_prefix(
967
961
  error = read_prefix_1(out, db, &key, len, true);
968
962
 
969
963
  if (error == GIT_ENOTFOUND)
970
- return git_odb__error_notfound("no match for prefix", &key);
964
+ return git_odb__error_notfound("no match for prefix", &key, len);
971
965
 
972
966
  return error;
973
967
  }
@@ -1223,12 +1217,14 @@ int git_odb_refresh(struct git_odb *db)
1223
1217
  return 0;
1224
1218
  }
1225
1219
 
1226
- int git_odb__error_notfound(const char *message, const git_oid *oid)
1220
+ int git_odb__error_notfound(
1221
+ const char *message, const git_oid *oid, size_t oid_len)
1227
1222
  {
1228
1223
  if (oid != NULL) {
1229
1224
  char oid_str[GIT_OID_HEXSZ + 1];
1230
- git_oid_tostr(oid_str, sizeof(oid_str), oid);
1231
- giterr_set(GITERR_ODB, "Object not found - %s (%s)", message, oid_str);
1225
+ git_oid_tostr(oid_str, oid_len+1, oid);
1226
+ giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
1227
+ message, oid_len, oid_str);
1232
1228
  } else
1233
1229
  giterr_set(GITERR_ODB, "Object not found - %s", message);
1234
1230
 
@@ -82,7 +82,8 @@ int git_odb__hashlink(git_oid *out, const char *path);
82
82
  /*
83
83
  * Generate a GIT_ENOTFOUND error for the ODB.
84
84
  */
85
- int git_odb__error_notfound(const char *message, const git_oid *oid);
85
+ int git_odb__error_notfound(
86
+ const char *message, const git_oid *oid, size_t oid_len);
86
87
 
87
88
  /*
88
89
  * Generate a GIT_EAMBIGUOUS error for the ODB.
@@ -91,7 +91,7 @@ static int object_mkdir(const git_buf *name, const loose_backend *be)
91
91
 
92
92
  static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
93
93
  {
94
- unsigned char c;
94
+ unsigned long c;
95
95
  unsigned char *data = (unsigned char *)obj->ptr;
96
96
  size_t shift, size, used = 0;
97
97
 
@@ -547,7 +547,8 @@ static int locate_object_short_oid(
547
547
 
548
548
  /* Check that directory exists */
549
549
  if (git_path_isdir(object_location->ptr) == false)
550
- return git_odb__error_notfound("no matching loose object for prefix", short_oid);
550
+ return git_odb__error_notfound("no matching loose object for prefix",
551
+ short_oid, len);
551
552
 
552
553
  state.dir_len = git_buf_len(object_location);
553
554
  state.short_oid_len = len;
@@ -560,7 +561,8 @@ static int locate_object_short_oid(
560
561
  return error;
561
562
 
562
563
  if (!state.found)
563
- return git_odb__error_notfound("no matching loose object for prefix", short_oid);
564
+ return git_odb__error_notfound("no matching loose object for prefix",
565
+ short_oid, len);
564
566
 
565
567
  if (state.found > 1)
566
568
  return git_odb__error_ambiguous("multiple matches in loose objects");
@@ -613,9 +615,10 @@ static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_
613
615
  raw.len = 0;
614
616
  raw.type = GIT_OBJ_BAD;
615
617
 
616
- if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
617
- error = git_odb__error_notfound("no matching loose object", oid);
618
- else if ((error = read_header_loose(&raw, &object_path)) == 0) {
618
+ if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
619
+ error = git_odb__error_notfound("no matching loose object",
620
+ oid, GIT_OID_HEXSZ);
621
+ } else if ((error = read_header_loose(&raw, &object_path)) == 0) {
619
622
  *len_p = raw.len;
620
623
  *type_p = raw.type;
621
624
  }
@@ -633,9 +636,10 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p
633
636
 
634
637
  assert(backend && oid);
635
638
 
636
- if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
637
- error = git_odb__error_notfound("no matching loose object", oid);
638
- else if ((error = read_loose(&raw, &object_path)) == 0) {
639
+ if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
640
+ error = git_odb__error_notfound("no matching loose object",
641
+ oid, GIT_OID_HEXSZ);
642
+ } else if ((error = read_loose(&raw, &object_path)) == 0) {
639
643
  *buffer_p = raw.data;
640
644
  *len_p = raw.len;
641
645
  *type_p = raw.type;
@@ -264,7 +264,8 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen
264
264
  if (!pack_entry_find_inner(e, backend, oid, last_found))
265
265
  return 0;
266
266
 
267
- return git_odb__error_notfound("failed to find pack entry", oid);
267
+ return git_odb__error_notfound(
268
+ "failed to find pack entry", oid, GIT_OID_HEXSZ);
268
269
  }
269
270
 
270
271
  static int pack_entry_find_prefix(
@@ -309,7 +310,8 @@ static int pack_entry_find_prefix(
309
310
  }
310
311
 
311
312
  if (!found)
312
- return git_odb__error_notfound("no matching pack entry for prefix", short_oid);
313
+ return git_odb__error_notfound("no matching pack entry for prefix",
314
+ short_oid, len);
313
315
  else
314
316
  return 0;
315
317
  }
@@ -333,7 +335,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
333
335
  return 0;
334
336
 
335
337
  if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
336
- return git_odb__error_notfound("failed to refresh packfiles", NULL);
338
+ return git_odb__error_notfound("failed to refresh packfiles", NULL, 0);
337
339
 
338
340
  git_buf_sets(&path, backend->pack_folder);
339
341
 
@@ -589,9 +591,6 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
589
591
  struct pack_backend *backend = NULL;
590
592
  git_buf path = GIT_BUF_INIT;
591
593
 
592
- if (git_mwindow_files_init() < 0)
593
- return -1;
594
-
595
594
  if (pack_backend__alloc(&backend, 8) < 0)
596
595
  return -1;
597
596
 
@@ -44,4 +44,13 @@ GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
44
44
  return git_oid__hashcmp(a->id, b->id);
45
45
  }
46
46
 
47
+ GIT_INLINE(void) git_oid__cpy_prefix(
48
+ git_oid *out, const git_oid *id, size_t len)
49
+ {
50
+ memcpy(&out->id, id->id, (len + 1) / 2);
51
+
52
+ if (len & 1)
53
+ out->id[len / 2] &= 0xF0;
54
+ }
55
+
47
56
  #endif
@@ -13,6 +13,7 @@
13
13
  #include "posix.h"
14
14
  #include "stream.h"
15
15
  #include "socket_stream.h"
16
+ #include "openssl_stream.h"
16
17
  #include "netops.h"
17
18
  #include "git2/transport.h"
18
19
  #include "git2/sys/openssl.h"
@@ -34,6 +35,8 @@
34
35
 
35
36
  SSL_CTX *git__ssl_ctx;
36
37
 
38
+ #define GIT_SSL_DEFAULT_CIPHERS "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES128-SHA256:DHE-DSS-AES256-SHA256:DHE-DSS-AES128-SHA:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA"
39
+
37
40
  #ifdef GIT_THREADS
38
41
 
39
42
  static git_mutex *openssl_locks;
@@ -69,12 +72,20 @@ static void shutdown_ssl_locking(void)
69
72
 
70
73
  #endif /* GIT_THREADS */
71
74
 
75
+ static BIO_METHOD *git_stream_bio_method;
76
+ static int init_bio_method(void);
77
+
72
78
  /**
73
79
  * This function aims to clean-up the SSL context which
74
80
  * we allocated.
75
81
  */
76
82
  static void shutdown_ssl(void)
77
83
  {
84
+ if (git_stream_bio_method) {
85
+ BIO_meth_free(git_stream_bio_method);
86
+ git_stream_bio_method = NULL;
87
+ }
88
+
78
89
  if (git__ssl_ctx) {
79
90
  SSL_CTX_free(git__ssl_ctx);
80
91
  git__ssl_ctx = NULL;
@@ -85,6 +96,7 @@ int git_openssl_stream_global_init(void)
85
96
  {
86
97
  #ifdef GIT_OPENSSL
87
98
  long ssl_opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
99
+ const char *ciphers = git_libgit2__ssl_ciphers();
88
100
 
89
101
  /* Older OpenSSL and MacOS OpenSSL doesn't have this */
90
102
  #ifdef SSL_OP_NO_COMPRESSION
@@ -108,6 +120,23 @@ int git_openssl_stream_global_init(void)
108
120
  git__ssl_ctx = NULL;
109
121
  return -1;
110
122
  }
123
+
124
+ if (!ciphers) {
125
+ ciphers = GIT_SSL_DEFAULT_CIPHERS;
126
+ }
127
+
128
+ if(!SSL_CTX_set_cipher_list(git__ssl_ctx, ciphers)) {
129
+ SSL_CTX_free(git__ssl_ctx);
130
+ git__ssl_ctx = NULL;
131
+ return -1;
132
+ }
133
+
134
+ if (init_bio_method() < 0) {
135
+ SSL_CTX_free(git__ssl_ctx);
136
+ git__ssl_ctx = NULL;
137
+ return -1;
138
+ }
139
+
111
140
  #endif
112
141
 
113
142
  git__on_shutdown(shutdown_ssl);
@@ -143,10 +172,8 @@ int git_openssl_set_locking(void)
143
172
 
144
173
  static int bio_create(BIO *b)
145
174
  {
146
- b->init = 1;
147
- b->num = 0;
148
- b->ptr = NULL;
149
- b->flags = 0;
175
+ BIO_set_init(b, 1);
176
+ BIO_set_data(b, NULL);
150
177
 
151
178
  return 1;
152
179
  }
@@ -156,23 +183,22 @@ static int bio_destroy(BIO *b)
156
183
  if (!b)
157
184
  return 0;
158
185
 
159
- b->init = 0;
160
- b->num = 0;
161
- b->ptr = NULL;
162
- b->flags = 0;
186
+ BIO_set_data(b, NULL);
163
187
 
164
188
  return 1;
165
189
  }
166
190
 
167
191
  static int bio_read(BIO *b, char *buf, int len)
168
192
  {
169
- git_stream *io = (git_stream *) b->ptr;
193
+ git_stream *io = (git_stream *) BIO_get_data(b);
194
+
170
195
  return (int) git_stream_read(io, buf, len);
171
196
  }
172
197
 
173
198
  static int bio_write(BIO *b, const char *buf, int len)
174
199
  {
175
- git_stream *io = (git_stream *) b->ptr;
200
+ git_stream *io = (git_stream *) BIO_get_data(b);
201
+
176
202
  return (int) git_stream_write(io, buf, len, 0);
177
203
  }
178
204
 
@@ -201,17 +227,22 @@ static int bio_puts(BIO *b, const char *str)
201
227
  return bio_write(b, str, strlen(str));
202
228
  }
203
229
 
204
- static BIO_METHOD git_stream_bio_method = {
205
- BIO_TYPE_SOURCE_SINK,
206
- "git_stream",
207
- bio_write,
208
- bio_read,
209
- bio_puts,
210
- bio_gets,
211
- bio_ctrl,
212
- bio_create,
213
- bio_destroy
214
- };
230
+ static int init_bio_method(void)
231
+ {
232
+ /* Set up the BIO_METHOD we use for wrapping our own stream implementations */
233
+ git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream");
234
+ GITERR_CHECK_ALLOC(git_stream_bio_method);
235
+
236
+ BIO_meth_set_write(git_stream_bio_method, bio_write);
237
+ BIO_meth_set_read(git_stream_bio_method, bio_read);
238
+ BIO_meth_set_puts(git_stream_bio_method, bio_puts);
239
+ BIO_meth_set_gets(git_stream_bio_method, bio_gets);
240
+ BIO_meth_set_ctrl(git_stream_bio_method, bio_ctrl);
241
+ BIO_meth_set_create(git_stream_bio_method, bio_create);
242
+ BIO_meth_set_destroy(git_stream_bio_method, bio_destroy);
243
+
244
+ return 0;
245
+ }
215
246
 
216
247
  static int ssl_set_error(SSL *ssl, int error)
217
248
  {
@@ -326,7 +357,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
326
357
  num = sk_GENERAL_NAME_num(alts);
327
358
  for (i = 0; i < num && matched != 1; i++) {
328
359
  const GENERAL_NAME *gn = sk_GENERAL_NAME_value(alts, i);
329
- const char *name = (char *) ASN1_STRING_data(gn->d.ia5);
360
+ const char *name = (char *) ASN1_STRING_get0_data(gn->d.ia5);
330
361
  size_t namelen = (size_t) ASN1_STRING_length(gn->d.ia5);
331
362
 
332
363
  /* Skip any names of a type we're not looking for */
@@ -381,7 +412,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
381
412
  if (size > 0) {
382
413
  peer_cn = OPENSSL_malloc(size + 1);
383
414
  GITERR_CHECK_ALLOC(peer_cn);
384
- memcpy(peer_cn, ASN1_STRING_data(str), size);
415
+ memcpy(peer_cn, ASN1_STRING_get0_data(str), size);
385
416
  peer_cn[size] = '\0';
386
417
  } else {
387
418
  goto cert_fail_name;
@@ -432,11 +463,12 @@ int openssl_connect(git_stream *stream)
432
463
 
433
464
  st->connected = true;
434
465
 
435
- bio = BIO_new(&git_stream_bio_method);
466
+ bio = BIO_new(git_stream_bio_method);
436
467
  GITERR_CHECK_ALLOC(bio);
437
- bio->ptr = st->io;
438
468
 
469
+ BIO_set_data(bio, st->io);
439
470
  SSL_set_bio(st->ssl, bio, bio);
471
+
440
472
  /* specify the host in case SNI is needed */
441
473
  #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
442
474
  SSL_set_tlsext_host_name(st->ssl, st->host);
@@ -509,8 +541,9 @@ ssize_t openssl_read(git_stream *stream, void *data, size_t len)
509
541
  openssl_stream *st = (openssl_stream *) stream;
510
542
  int ret;
511
543
 
512
- if ((ret = SSL_read(st->ssl, data, len)) <= 0)
513
- ssl_set_error(st->ssl, ret);
544
+ if ((ret = SSL_read(st->ssl, data, len)) <= 0) {
545
+ return ssl_set_error(st->ssl, ret);
546
+ }
514
547
 
515
548
  return ret;
516
549
  }