annotate src/os_qnx.c @ 33262:6eac4f616293 v9.0.1899

patch 9.0.1899: potential buffer overflow in PBYTE macro Commit: https://github.com/vim/vim/commit/ffb13674d1af1c90beb229867ec989e4fb232df3 Author: Christian Brabandt <cb@256bit.org> Date: Fri Sep 15 20:22:02 2023 +0200 patch 9.0.1899: potential buffer overflow in PBYTE macro Problem: potential buffer overflow in PBYTE macro Solution: Check returned memline length closes: #13083 the PBYTE macro is used to put byte c at a position lp of the returned memline. However, in case of unexpected errors ml_get_buf() may return either "???" or an empty line in which case it is quite likely that we are causing a buffer overrun. Therefore, switch the macro PBYTE (which is only used in ops.c anyhow) to a function, that verifies that we will only try to access within the given length of the buffer. Also, since the macro is only used in ops.c, move the definition from macros.h to ops.c Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Fri, 15 Sep 2023 20:30:07 +0200
parents 97255d909654
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * QNX port by Julian Kinraid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 * os_qnx.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #if defined(FEAT_GUI_PHOTON)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 int is_photon_available;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 5735
diff changeset
22 void qnx_init(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #if defined(FEAT_GUI_PHOTON)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 PhChannelParms_t parms;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
32120
97255d909654 patch 9.0.1391: "clear" macros are not always used
Bram Moolenaar <Bram@vim.org>
parents: 31752
diff changeset
27 CLEAR_FIELD(parms);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 parms.flags = Ph_DYNAMIC_BUFFER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
30 is_photon_available = (PhAttach(NULL, &parms) != NULL) ? TRUE : FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 #if (defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #define CLIP_TYPE_VIM "VIMTYPE"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 #define CLIP_TYPE_TEXT "TEXT"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
18810
44b855153d8e patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17063
diff changeset
39 // Turn on the clipboard for a console vim when photon is running
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 5735
diff changeset
40 void qnx_clip_init(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 {
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
42 if (is_photon_available == TRUE && !gui.in_use)
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
43 clip_init(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
18810
44b855153d8e patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17063
diff changeset
46 /////////////////////////////////////////////////////////////////////////////
44b855153d8e patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17063
diff changeset
47 // Clipboard
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
18810
44b855153d8e patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17063
diff changeset
49 // No support for owning the clipboard
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 int
17063
3147c7c2e86b patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
51 clip_mch_own_selection(Clipboard_T *cbd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 void
17063
3147c7c2e86b patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
57 clip_mch_lose_selection(Clipboard_T *cbd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 void
17063
3147c7c2e86b patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
62 clip_mch_request_selection(Clipboard_T *cbd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 int type = MLINE, clip_length = 0, is_type_set = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 void *cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 PhClipHeader *clip_header;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 char_u *clip_text = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
69 cbdata = PhClipboardPasteStart(PhInputGroup(NULL));
31752
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
70 if (cbdata == NULL)
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
71 return;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
31752
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
73 // Look for the vim specific clip first
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
74 clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM);
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
75 if (clip_header != NULL && clip_header->data != NULL)
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
76 {
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
77 switch(*(char *) clip_header->data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 {
31752
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
79 default: // fallthrough to line type
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
80 case 'L': type = MLINE; break;
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
81 case 'C': type = MCHAR; break;
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
82 case 'B': type = MBLOCK; break;
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
83 }
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
84 is_type_set = TRUE;
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
85 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
31752
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
87 // Try for just normal text
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
88 clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT);
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
89 if (clip_header != NULL)
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
90 {
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
91 clip_text = clip_header->data;
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
92 clip_length = clip_header->length - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
31752
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
94 if (clip_text != NULL && is_type_set == FALSE)
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
95 type = MAUTO;
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
96 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97
31752
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
98 if ((clip_text != NULL) && (clip_length > 0))
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
99 clip_yank_selection(type, clip_text, clip_length, cbd);
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
100
3365a601e73b patch 9.0.1208: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18810
diff changeset
101 PhClipboardPasteFinish(cbdata);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 void
17063
3147c7c2e86b patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
105 clip_mch_set_selection(Clipboard_T *cbd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 long_u len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 char_u *text_clip, vim_clip[2], *str = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 PhClipHeader clip_header[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
18810
44b855153d8e patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17063
diff changeset
112 // Prevent recursion from clip_get_selection()
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
113 if (cbd->owned == TRUE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 cbd->owned = TRUE;
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
117 clip_get_selection(cbd);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 cbd->owned = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
120 type = clip_convert_selection(&str, &len, cbd);
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
121 if (type >= 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 {
16768
695d9ef00b03 patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
123 text_clip = alloc(len + 1); // Normal text
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
125 if (text_clip && vim_clip)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 {
32120
97255d909654 patch 9.0.1391: "clear" macros are not always used
Bram Moolenaar <Bram@vim.org>
parents: 31752
diff changeset
127 CLEAR_FIELD(clip_header);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
129 STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8);
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
130 clip_header[0].length = sizeof(vim_clip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 clip_header[0].data = vim_clip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
133 STRNCPY(clip_header[1].type, CLIP_TYPE_TEXT, 8);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 clip_header[1].length = len + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 clip_header[1].data = text_clip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
137 switch(type)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 {
18810
44b855153d8e patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17063
diff changeset
139 default: // fallthrough to MLINE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 case MLINE: *vim_clip = 'L'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 case MCHAR: *vim_clip = 'C'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 case MBLOCK: *vim_clip = 'B'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
145 vim_strncpy(text_clip, str, len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 vim_clip[ 1 ] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
149 PhClipboardCopy(PhInputGroup(NULL), 2, clip_header);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 }
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
151 vim_free(text_clip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 }
3100
fc0804089b29 updated for version 7.3.321
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
153 vim_free(str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 #endif