• R/O
  • SSH

vim: コミット

Mirror of the Vim source from https://github.com/vim/vim


コミットメタ情報

リビジョンe1cedf00992028931e579ebb50be8b8ddb95bd1f (tree)
日時2022-01-19 22:45:05
作者Bram Moolenaar <Bram@vim....>
コミッターBram Moolenaar

ログメッセージ

patch 8.2.4144: cannot load libsodium dynamically

Commit: https://github.com/vim/vim/commit/1a8825d7a3484d76ca16ea2aa9769cadca7758a4
Author: K.Takata <kentkt@csc.jp>
Date: Wed Jan 19 13:32:57 2022 +0000

patch 8.2.4144: cannot load libsodium dynamically
Problem: Cannot load libsodium dynamically.
Solution: Support dynamic loading on MS-Windows. (Ken Takata, closes https://github.com/vim/vim/issues/9554)

変更サマリ

差分

diff -r c405d50702b1 -r e1cedf009920 src/Make_cyg_ming.mak
--- a/src/Make_cyg_ming.mak Wed Jan 19 14:00:05 2022 +0100
+++ b/src/Make_cyg_ming.mak Wed Jan 19 14:45:05 2022 +0100
@@ -668,7 +668,14 @@
668668 endif
669669
670670 ifeq ($(SODIUM),yes)
671+ ifndef DYNAMIC_SODIUM
672+DYNAMIC_SODIUM=yes
673+ endif
674+ ifeq ($(DYNAMIC_SODIUM),yes)
675+DEFINES += -DDYNAMIC_SODIUM
676+ else
671677 SODIUMLIB = -lsodium
678+ endif
672679 endif
673680
674681 # Only allow XPM for a GUI build.
diff -r c405d50702b1 -r e1cedf009920 src/Make_mvc.mak
--- a/src/Make_mvc.mak Wed Jan 19 14:00:05 2022 +0100
+++ b/src/Make_mvc.mak Wed Jan 19 14:45:05 2022 +0100
@@ -42,10 +42,10 @@
4242 # Sound support: SOUND=yes (default is yes)
4343 #
4444 # Sodium support: SODIUM=[Path to Sodium directory]
45-# Dynamic built with libsodium
46-# You need to install the msvc package from
47-# https://download.libsodium.org/libsodium/releases/
48-# and package the libsodium.dll with Vim
45+# DYNAMIC_SODIUM=yes (to load the Sodium DLL dynamically)
46+# You need to install the msvc package from
47+# https://download.libsodium.org/libsodium/releases/
48+# and package the libsodium.dll with Vim
4949 #
5050 #
5151 # DLL support (EXPERIMENTAL): VIMDLL=yes (default is no)
@@ -384,6 +384,9 @@
384384 !ifndef SODIUM
385385 SODIUM = no
386386 !endif
387+!ifndef DYNAMIC_SODIUM
388+DYNAMIC_SODIUM = yes
389+!endif
387390
388391 !if "$(SODIUM)" != "no"
389392 ! if "$(CPU)" == "AMD64"
@@ -397,8 +400,13 @@
397400
398401 !if "$(SODIUM)" != "no"
399402 SOD_INC = /I "$(SODIUM)\include"
403+! if "$(DYNAMIC_SODIUM)" == "yes"
404+SOD_DEFS = -DHAVE_SODIUM -DDYNAMIC_SODIUM
405+SOD_LIB =
406+! else
400407 SOD_DEFS = -DHAVE_SODIUM
401408 SOD_LIB = $(SOD_LIB)\libsodium.lib
409+! endif
402410 !endif
403411
404412 !ifndef NETBEANS
diff -r c405d50702b1 -r e1cedf009920 src/buffer.c
--- a/src/buffer.c Wed Jan 19 14:00:05 2022 +0100
+++ b/src/buffer.c Wed Jan 19 14:45:05 2022 +0100
@@ -2269,8 +2269,9 @@
22692269 #endif
22702270 #ifdef FEAT_CRYPT
22712271 # ifdef FEAT_SODIUM
2272- if (buf->b_p_key != NULL && (crypt_get_method_nr(buf) == CRYPT_M_SOD))
2273- sodium_munlock(buf->b_p_key, STRLEN(buf->b_p_key));
2272+ if ((buf->b_p_key != NULL) && (*buf->b_p_key != NUL) &&
2273+ (crypt_get_method_nr(buf) == CRYPT_M_SOD))
2274+ crypt_sodium_munlock(buf->b_p_key, STRLEN(buf->b_p_key));
22742275 # endif
22752276 clear_string_option(&buf->b_p_key);
22762277 #endif
diff -r c405d50702b1 -r e1cedf009920 src/crypt.c
--- a/src/crypt.c Wed Jan 19 14:00:05 2022 +0100
+++ b/src/crypt.c Wed Jan 19 14:45:05 2022 +0100
@@ -159,6 +159,108 @@
159159 crypto_secretstream_xchacha20poly1305_state
160160 state;
161161 } sodium_state_T;
162+
163+
164+# ifdef DYNAMIC_SODIUM
165+# define sodium_init load_sodium
166+# define sodium_free dll_sodium_free
167+# define sodium_malloc dll_sodium_malloc
168+# define sodium_memzero dll_sodium_memzero
169+# define sodium_mlock dll_sodium_mlock
170+# define sodium_munlock dll_sodium_munlock
171+# define crypto_secretstream_xchacha20poly1305_init_push \
172+ dll_crypto_secretstream_xchacha20poly1305_init_push
173+# define crypto_secretstream_xchacha20poly1305_push \
174+ dll_crypto_secretstream_xchacha20poly1305_push
175+# define crypto_secretstream_xchacha20poly1305_init_pull \
176+ dll_crypto_secretstream_xchacha20poly1305_init_pull
177+# define crypto_secretstream_xchacha20poly1305_pull \
178+ dll_crypto_secretstream_xchacha20poly1305_pull
179+# define crypto_pwhash dll_crypto_pwhash
180+# define randombytes_buf dll_randombytes_buf
181+
182+static int (*dll_sodium_init)(void) = NULL;
183+static void (*dll_sodium_free)(void *) = NULL;
184+static void *(*dll_sodium_malloc)(const size_t) = NULL;
185+static void (*dll_sodium_memzero)(void * const, const size_t) = NULL;
186+static int (*dll_sodium_mlock)(void * const, const size_t) = NULL;
187+static int (*dll_sodium_munlock)(void * const, const size_t) = NULL;
188+static int (*dll_crypto_secretstream_xchacha20poly1305_init_push)
189+ (crypto_secretstream_xchacha20poly1305_state *state,
190+ unsigned char [],
191+ const unsigned char []) = NULL;
192+static int (*dll_crypto_secretstream_xchacha20poly1305_push)
193+ (crypto_secretstream_xchacha20poly1305_state *state,
194+ unsigned char *c, unsigned long long *clen_p,
195+ const unsigned char *m, unsigned long long mlen,
196+ const unsigned char *ad, unsigned long long adlen, unsigned char tag)
197+ = NULL;
198+static int (*dll_crypto_secretstream_xchacha20poly1305_init_pull)
199+ (crypto_secretstream_xchacha20poly1305_state *state,
200+ const unsigned char [],
201+ const unsigned char []) = NULL;
202+static int (*dll_crypto_secretstream_xchacha20poly1305_pull)
203+ (crypto_secretstream_xchacha20poly1305_state *state,
204+ unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,
205+ const unsigned char *c, unsigned long long clen,
206+ const unsigned char *ad, unsigned long long adlen) = NULL;
207+static int (*dll_crypto_pwhash)(unsigned char * const out,
208+ unsigned long long outlen,
209+ const char * const passwd, unsigned long long passwdlen,
210+ const unsigned char * const salt,
211+ unsigned long long opslimit, size_t memlimit, int alg)
212+ = NULL;
213+static void (*dll_randombytes_buf)(void * const buf, const size_t size);
214+
215+static struct {
216+ const char *name;
217+ FARPROC *ptr;
218+} sodium_funcname_table[] = {
219+ {"sodium_init", (FARPROC*)&dll_sodium_init},
220+ {"sodium_free", (FARPROC*)&dll_sodium_free},
221+ {"sodium_malloc", (FARPROC*)&dll_sodium_malloc},
222+ {"sodium_memzero", (FARPROC*)&dll_sodium_memzero},
223+ {"sodium_mlock", (FARPROC*)&dll_sodium_mlock},
224+ {"sodium_munlock", (FARPROC*)&dll_sodium_munlock},
225+ {"crypto_secretstream_xchacha20poly1305_init_push", (FARPROC*)&dll_crypto_secretstream_xchacha20poly1305_init_push},
226+ {"crypto_secretstream_xchacha20poly1305_push", (FARPROC*)&dll_crypto_secretstream_xchacha20poly1305_push},
227+ {"crypto_secretstream_xchacha20poly1305_init_pull", (FARPROC*)&dll_crypto_secretstream_xchacha20poly1305_init_pull},
228+ {"crypto_secretstream_xchacha20poly1305_pull", (FARPROC*)&dll_crypto_secretstream_xchacha20poly1305_pull},
229+ {"crypto_pwhash", (FARPROC*)&dll_crypto_pwhash},
230+ {"randombytes_buf", (FARPROC*)&dll_randombytes_buf},
231+ {NULL, NULL}
232+};
233+
234+ static int
235+load_sodium(void)
236+{
237+ static HANDLE hsodium = NULL;
238+ int i;
239+
240+ if (hsodium != NULL)
241+ return 0;
242+
243+ hsodium = vimLoadLib("libsodium.dll");
244+ if (hsodium == NULL)
245+ {
246+ // TODO: Show error message.
247+ return -1;
248+ }
249+
250+ for (i = 0; sodium_funcname_table[i].ptr; ++i)
251+ {
252+ if ((*sodium_funcname_table[i].ptr = GetProcAddress(hsodium,
253+ sodium_funcname_table[i].name)) == NULL)
254+ {
255+ FreeLibrary(hsodium);
256+ hsodium = NULL;
257+ // TODO: Show error message.
258+ return -1;
259+ }
260+ }
261+ return dll_sodium_init();
262+}
263+# endif
162264 #endif
163265
164266 #define CRYPT_MAGIC_LEN 12 // cannot change
@@ -990,4 +1092,18 @@
9901092 # endif
9911093 }
9921094
1095+# if defined(FEAT_SODIUM) || defined(PROTO)
1096+ int
1097+crypt_sodium_munlock(void *const addr, const size_t len)
1098+{
1099+ return sodium_munlock(addr, len);
1100+}
1101+
1102+ void
1103+crypt_sodium_randombytes_buf(void *const buf, const size_t size)
1104+{
1105+ randombytes_buf(buf, size);
1106+}
1107+# endif
1108+
9931109 #endif // FEAT_CRYPT
diff -r c405d50702b1 -r e1cedf009920 src/memline.c
--- a/src/memline.c Wed Jan 19 14:00:05 2022 +0100
+++ b/src/memline.c Wed Jan 19 14:45:05 2022 +0100
@@ -436,7 +436,8 @@
436436 }
437437 #ifdef FEAT_SODIUM
438438 else if (method_nr == CRYPT_M_SOD)
439- randombytes_buf(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN);
439+ crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed,
440+ MF_SEED_LEN);
440441 #endif
441442 }
442443 }
diff -r c405d50702b1 -r e1cedf009920 src/proto/crypt.pro
--- a/src/proto/crypt.pro Wed Jan 19 14:00:05 2022 +0100
+++ b/src/proto/crypt.pro Wed Jan 19 14:45:05 2022 +0100
@@ -26,4 +26,6 @@
2626 int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len);
2727 long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last);
2828 long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last);
29+int crypt_sodium_munlock(void *const addr, const size_t len);
30+void crypt_sodium_randombytes_buf(void *const buf, const size_t size);
2931 /* vim: set ft=c : */
diff -r c405d50702b1 -r e1cedf009920 src/version.c
--- a/src/version.c Wed Jan 19 14:00:05 2022 +0100
+++ b/src/version.c Wed Jan 19 14:45:05 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4144,
755+/**/
754756 4143,
755757 /**/
756758 4142,
旧リポジトリブラウザで表示