Skip to content

Commit 731d065

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents bbe62c1 + 1662ce1 commit 731d065

File tree

19 files changed

+307
-113
lines changed

19 files changed

+307
-113
lines changed

runtime/doc/eval.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6320,15 +6320,17 @@ reltimestr({time}) *reltimestr()*
63206320
{only available when compiled with the |+reltime| feature}
63216321

63226322
*remote_expr()* *E449*
6323-
remote_expr({server}, {string} [, {idvar}])
6323+
remote_expr({server}, {string} [, {idvar} [, {timeout}]])
63246324
Send the {string} to {server}. The string is sent as an
63256325
expression and the result is returned after evaluation.
63266326
The result must be a String or a |List|. A |List| is turned
63276327
into a String by joining the items with a line break in
63286328
between (not at the end), like with join(expr, "\n").
6329-
If {idvar} is present, it is taken as the name of a
6330-
variable and a {serverid} for later use with
6329+
If {idvar} is present and not empty, it is taken as the name
6330+
of a variable and a {serverid} for later use with
63316331
remote_read() is stored there.
6332+
If {timeout} is given the read times out after this many
6333+
seconds. Otherwise a timeout of 600 seconds is used.
63326334
See also |clientserver| |RemoteReply|.
63336335
This function is not available in the |sandbox|.
63346336
{only available when compiled with the |+clientserver| feature}
@@ -6367,9 +6369,10 @@ remote_peek({serverid} [, {retvar}]) *remote_peek()*
63676369
:let repl = ""
63686370
:echo "PEEK: ".remote_peek(id, "repl").": ".repl
63696371
6370-
remote_read({serverid}) *remote_read()*
6372+
remote_read({serverid}, [{timeout}]) *remote_read()*
63716373
Return the oldest available reply from {serverid} and consume
6372-
it. It blocks until a reply is available.
6374+
it. Unless a {timeout} in seconds is given, it blocks until a
6375+
reply is available.
63736376
See also |clientserver|.
63746377
This function is not available in the |sandbox|.
63756378
{only available when compiled with the |+clientserver| feature}

src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,7 @@ test_arglist \
21132113
test_backspace_opt \
21142114
test_breakindent \
21152115
test_bufwintabinfo \
2116+
test_cd \
21162117
test_cdo \
21172118
test_changedtick \
21182119
test_channel \
@@ -2202,6 +2203,7 @@ test_arglist \
22022203
test_pyx2 \
22032204
test_pyx3 \
22042205
test_quickfix \
2206+
test_quotestar \
22052207
test_recover \
22062208
test_regexp_latin \
22072209
test_regexp_utf8 \

src/evalfunc.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,10 @@ static struct fst
739739
{"reltimefloat", 1, 1, f_reltimefloat},
740740
#endif
741741
{"reltimestr", 1, 1, f_reltimestr},
742-
{"remote_expr", 2, 3, f_remote_expr},
742+
{"remote_expr", 2, 4, f_remote_expr},
743743
{"remote_foreground", 1, 1, f_remote_foreground},
744744
{"remote_peek", 1, 2, f_remote_peek},
745-
{"remote_read", 1, 1, f_remote_read},
745+
{"remote_read", 1, 2, f_remote_read},
746746
{"remote_send", 2, 3, f_remote_send},
747747
{"remote_startserver", 1, 1, f_remote_startserver},
748748
{"remove", 2, 3, f_remove},
@@ -8534,6 +8534,7 @@ remote_common(typval_T *argvars, typval_T *rettv, int expr)
85348534
char_u *keys;
85358535
char_u *r = NULL;
85368536
char_u buf[NUMBUFLEN];
8537+
int timeout = 0;
85378538
# ifdef WIN32
85388539
HWND w;
85398540
# elif defined(FEAT_X11)
@@ -8549,18 +8550,19 @@ remote_common(typval_T *argvars, typval_T *rettv, int expr)
85498550
if (check_connection() == FAIL)
85508551
return;
85518552
# endif
8553+
if (argvars[2].v_type != VAR_UNKNOWN
8554+
&& argvars[3].v_type != VAR_UNKNOWN)
8555+
timeout = get_tv_number(&argvars[3]);
85528556

85538557
server_name = get_tv_string_chk(&argvars[0]);
85548558
if (server_name == NULL)
85558559
return; /* type error; errmsg already given */
85568560
keys = get_tv_string_buf(&argvars[1], buf);
8557-
# ifdef WIN32
8558-
if (serverSendToVim(server_name, keys, &r, &w, expr, TRUE) < 0)
8559-
# elif defined(FEAT_X11)
8560-
if (serverSendToVim(X_DISPLAY, server_name, keys, &r, &w, expr, 0, TRUE)
8561-
< 0)
8562-
# elif defined(MAC_CLIENTSERVER)
8563-
if (serverSendToVim(server_name, keys, &r, &w, expr, TRUE) < 0)
8561+
# if defined(WIN32) || defined(MAC_CLIENTSERVER)
8562+
if (serverSendToVim(server_name, keys, &r, &w, expr, timeout, TRUE) < 0)
8563+
# else
8564+
if (serverSendToVim(X_DISPLAY, server_name, keys, &r, &w, expr, timeout,
8565+
0, TRUE) < 0)
85648566
# endif
85658567
{
85668568
if (r != NULL)
@@ -8578,13 +8580,15 @@ remote_common(typval_T *argvars, typval_T *rettv, int expr)
85788580
char_u str[30];
85798581
char_u *idvar;
85808582

8581-
sprintf((char *)str, PRINTF_HEX_LONG_U, (long_u)w);
8582-
v.di_tv.v_type = VAR_STRING;
8583-
v.di_tv.vval.v_string = vim_strsave(str);
85848583
idvar = get_tv_string_chk(&argvars[2]);
8585-
if (idvar != NULL)
8584+
if (idvar != NULL && *idvar != NUL)
8585+
{
8586+
sprintf((char *)str, PRINTF_HEX_LONG_U, (long_u)w);
8587+
v.di_tv.v_type = VAR_STRING;
8588+
v.di_tv.vval.v_string = vim_strsave(str);
85868589
set_var(idvar, &v.di_tv, FALSE);
8587-
vim_free(v.di_tv.vval.v_string);
8590+
vim_free(v.di_tv.vval.v_string);
8591+
}
85888592
}
85898593
}
85908594
#endif
@@ -8656,7 +8660,7 @@ f_remote_peek(typval_T *argvars UNUSED, typval_T *rettv)
86568660
rettv->vval.v_number = -1;
86578661
else
86588662
{
8659-
s = serverGetReply((HWND)n, FALSE, FALSE, FALSE);
8663+
s = serverGetReply((HWND)n, FALSE, FALSE, FALSE, 0);
86608664
rettv->vval.v_number = (s != NULL);
86618665
}
86628666
# elif defined(FEAT_X11)
@@ -8695,19 +8699,26 @@ f_remote_read(typval_T *argvars UNUSED, typval_T *rettv)
86958699

86968700
if (serverid != NULL && !check_restricted() && !check_secure())
86978701
{
8702+
int timeout = 0;
86988703
# ifdef WIN32
86998704
/* The server's HWND is encoded in the 'id' parameter */
87008705
long_u n = 0;
8706+
# endif
8707+
8708+
if (argvars[1].v_type != VAR_UNKNOWN)
8709+
timeout = get_tv_number(&argvars[1]);
87018710

8711+
# ifdef WIN32
87028712
sscanf((char *)serverid, SCANF_HEX_LONG_U, &n);
87038713
if (n != 0)
8704-
r = serverGetReply((HWND)n, FALSE, TRUE, TRUE);
8714+
r = serverGetReply((HWND)n, FALSE, TRUE, TRUE, timeout);
87058715
if (r == NULL)
8706-
# elif defined(FEAT_X11)
8707-
if (check_connection() == FAIL || serverReadReply(X_DISPLAY,
8708-
serverStrToWin(serverid), &r, FALSE) < 0)
87098716
# elif defined(MAC_CLIENTSERVER)
87108717
if (serverReadReply(serverStrToPort(serverid), &r) < 0)
8718+
# else
8719+
if (check_connection() == FAIL
8720+
|| serverReadReply(X_DISPLAY, serverStrToWin(serverid),
8721+
&r, FALSE, timeout) < 0)
87118722
# endif
87128723
EMSG(_("E277: Unable to read a server reply"));
87138724
}

src/if_xcmdsrv.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ serverSendToVim(
374374
char_u **result, /* Result of eval'ed expression */
375375
Window *server, /* Actual ID of receiving app */
376376
Bool asExpr, /* Interpret as keystrokes or expr ? */
377+
int timeout, /* seconds to wait or zero */
377378
Bool localLoop, /* Throw away everything but result */
378379
int silent) /* don't complain about no server */
379380
{
@@ -486,7 +487,8 @@ serverSendToVim(
486487
pending.nextPtr = pendingCommands;
487488
pendingCommands = &pending;
488489

489-
ServerWait(dpy, w, WaitForPend, &pending, localLoop, 600);
490+
ServerWait(dpy, w, WaitForPend, &pending, localLoop,
491+
timeout > 0 ? timeout : 600);
490492

491493
/*
492494
* Unregister the information about the pending command
@@ -791,6 +793,7 @@ WaitForReply(void *p)
791793

792794
/*
793795
* Wait for replies from id (win)
796+
* When "timeout" is non-zero wait up to this many seconds.
794797
* Return 0 and the malloc'ed string when a reply is available.
795798
* Return -1 if the window becomes invalid while waiting.
796799
*/
@@ -799,13 +802,15 @@ serverReadReply(
799802
Display *dpy,
800803
Window win,
801804
char_u **str,
802-
int localLoop)
805+
int localLoop,
806+
int timeout)
803807
{
804808
int len;
805809
char_u *s;
806810
struct ServerReply *p;
807811

808-
ServerWait(dpy, win, WaitForReply, &win, localLoop, -1);
812+
ServerWait(dpy, win, WaitForReply, &win, localLoop,
813+
timeout > 0 ? timeout : -1);
809814

810815
if ((p = ServerReplyFind(win, SROP_Find)) != NULL && p->strings.ga_len > 0)
811816
{

src/main.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,10 +3877,10 @@ cmdsrv_main(
38773877
}
38783878
else
38793879
ret = serverSendToVim(xterm_dpy, sname, *serverStr,
3880-
NULL, &srv, 0, 0, silent);
3881-
# elif defined(WIN32) || defined(MAC_CLIENTSERVER)
3880+
NULL, &srv, 0, 0, 0, silent);
3881+
# else
38823882
/* Win32 always works? */
3883-
ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, silent);
3883+
ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, 0, silent);
38843884
# endif
38853885
if (ret < 0)
38863886
{
@@ -3940,11 +3940,11 @@ cmdsrv_main(
39403940
while (memchr(done, 0, numFiles) != NULL)
39413941
{
39423942
# ifdef WIN32
3943-
p = serverGetReply(srv, NULL, TRUE, TRUE);
3943+
p = serverGetReply(srv, NULL, TRUE, TRUE, 0);
39443944
if (p == NULL)
39453945
break;
3946-
# elif defined(FEAT_X11)
3947-
if (serverReadReply(xterm_dpy, srv, &p, TRUE) < 0)
3946+
# else
3947+
if (serverReadReply(xterm_dpy, srv, &p, TRUE, -1) < 0)
39483948
break;
39493949
# elif defined(MAC_CLIENTSERVER)
39503950
if (serverReadReply(srv, &p) < 0)
@@ -3971,18 +3971,15 @@ cmdsrv_main(
39713971
{
39723972
if (i == *argc - 1)
39733973
mainerr_arg_missing((char_u *)argv[i]);
3974-
# ifdef WIN32
3974+
# if defined(WIN32) || defined(MAC_CLIENTSERVER)
39753975
/* Win32 always works? */
39763976
if (serverSendToVim(sname, (char_u *)argv[i + 1],
3977-
&res, NULL, 1, FALSE) < 0)
3978-
# elif defined(FEAT_X11)
3977+
&res, NULL, 1, 0, FALSE) < 0)
3978+
# else
39793979
if (xterm_dpy == NULL)
39803980
mch_errmsg(_("No display: Send expression failed.\n"));
39813981
else if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1],
3982-
&res, NULL, 1, 1, FALSE) < 0)
3983-
# elif defined(MAC_CLIENTSERVER)
3984-
if (serverSendToVim(sname, (char_u *)argv[i + 1],
3985-
&res, NULL, 1, FALSE) < 0)
3982+
&res, NULL, 1, 0, 1, FALSE) < 0)
39863983
# endif
39873984
{
39883985
if (res != NULL && *res != NUL)
@@ -4286,7 +4283,7 @@ sendToLocalVim(char_u *cmd, int asExpr, char_u **result)
42864283
size_t len = STRLEN(cmd) + STRLEN(err) + 5;
42874284
char_u *msg;
42884285

4289-
msg = alloc(len);
4286+
msg = alloc((unsigned)len);
42904287
if (msg != NULL)
42914288
vim_snprintf((char *)msg, len, "%s: \"%s\"", err, cmd);
42924289
*result = msg;

src/misc2.c

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,13 +4643,23 @@ vim_findfile(void *search_ctx_arg)
46434643
if (!vim_isAbsName(stackp->ffs_fix_path)
46444644
&& search_ctx->ffsc_start_dir)
46454645
{
4646-
STRCPY(file_path, search_ctx->ffsc_start_dir);
4647-
add_pathsep(file_path);
4646+
if (STRLEN(search_ctx->ffsc_start_dir) + 1 < MAXPATHL)
4647+
{
4648+
STRCPY(file_path, search_ctx->ffsc_start_dir);
4649+
add_pathsep(file_path);
4650+
}
4651+
else
4652+
goto fail;
46484653
}
46494654

46504655
/* append the fix part of the search path */
4651-
STRCAT(file_path, stackp->ffs_fix_path);
4652-
add_pathsep(file_path);
4656+
if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 < MAXPATHL)
4657+
{
4658+
STRCAT(file_path, stackp->ffs_fix_path);
4659+
add_pathsep(file_path);
4660+
}
4661+
else
4662+
goto fail;
46534663

46544664
#ifdef FEAT_PATH_EXTRA
46554665
rest_of_wildcards = stackp->ffs_wc_path;
@@ -4666,7 +4676,10 @@ vim_findfile(void *search_ctx_arg)
46664676
if (*p > 0)
46674677
{
46684678
(*p)--;
4669-
file_path[len++] = '*';
4679+
if (len + 1 < MAXPATHL)
4680+
file_path[len++] = '*';
4681+
else
4682+
goto fail;
46704683
}
46714684

46724685
if (*p == 0)
@@ -4694,7 +4707,10 @@ vim_findfile(void *search_ctx_arg)
46944707
*/
46954708
while (*rest_of_wildcards
46964709
&& !vim_ispathsep(*rest_of_wildcards))
4697-
file_path[len++] = *rest_of_wildcards++;
4710+
if (len + 1 < MAXPATHL)
4711+
file_path[len++] = *rest_of_wildcards++;
4712+
else
4713+
goto fail;
46984714

46994715
file_path[len] = NUL;
47004716
if (vim_ispathsep(*rest_of_wildcards))
@@ -4755,9 +4771,15 @@ vim_findfile(void *search_ctx_arg)
47554771

47564772
/* prepare the filename to be checked for existence
47574773
* below */
4758-
STRCPY(file_path, stackp->ffs_filearray[i]);
4759-
add_pathsep(file_path);
4760-
STRCAT(file_path, search_ctx->ffsc_file_to_search);
4774+
if (STRLEN(stackp->ffs_filearray[i]) + 1
4775+
+ STRLEN(search_ctx->ffsc_file_to_search) < MAXPATHL)
4776+
{
4777+
STRCPY(file_path, stackp->ffs_filearray[i]);
4778+
add_pathsep(file_path);
4779+
STRCAT(file_path, search_ctx->ffsc_file_to_search);
4780+
}
4781+
else
4782+
goto fail;
47614783

47624784
/*
47634785
* Try without extra suffix and then with suffixes
@@ -4930,9 +4952,15 @@ vim_findfile(void *search_ctx_arg)
49304952
if (*search_ctx->ffsc_start_dir == 0)
49314953
break;
49324954

4933-
STRCPY(file_path, search_ctx->ffsc_start_dir);
4934-
add_pathsep(file_path);
4935-
STRCAT(file_path, search_ctx->ffsc_fix_path);
4955+
if (STRLEN(search_ctx->ffsc_start_dir) + 1
4956+
+ STRLEN(search_ctx->ffsc_fix_path) < MAXPATHL)
4957+
{
4958+
STRCPY(file_path, search_ctx->ffsc_start_dir);
4959+
add_pathsep(file_path);
4960+
STRCAT(file_path, search_ctx->ffsc_fix_path);
4961+
}
4962+
else
4963+
goto fail;
49364964

49374965
/* create a new stack entry */
49384966
sptr = ff_create_stack_element(file_path,
@@ -4946,6 +4974,7 @@ vim_findfile(void *search_ctx_arg)
49464974
}
49474975
#endif
49484976

4977+
fail:
49494978
vim_free(file_path);
49504979
return NULL;
49514980
}

0 commit comments

Comments
 (0)