summaryrefslogtreecommitdiff
path: root/external/firebird/ubsan.patch
blob: fa296108d3d6623dbaf9af9cf73665f4432c7f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
--- configure
+++ configure
@@ -21506,7 +21468,7 @@
     char a;
     union { long long x; sem_t y; } b;
   };
-  exit((int)&((struct s*)0)->b);
+  exit((int)&((struct s*)1024)->b - 1024);
 }
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
@@ -21541,7 +21503,7 @@
     char a;
     double b;
   };
-  exit((int)&((struct s*)0)->b);
+  exit((int)&((struct s*)1024)->b - 1024);
 }
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
--- src/common/classes/array.h
+++ src/common/classes/array.h
@@ -149,7 +149,7 @@
 	void copyFrom(const Array<T, Storage>& source)
 	{
 		ensureCapacity(source.count, false);
-		memcpy(data, source.data, sizeof(T) * source.count);
+		if (source.count != 0) memcpy(data, source.data, sizeof(T) * source.count);
 		count = source.count;
 	}
 
@@ -227,7 +227,7 @@
 		fb_assert(count <= FB_MAX_SIZEOF - itemsCount);
 		ensureCapacity(count + itemsCount);
 		memmove(data + index + itemsCount, data + index, sizeof(T) * (count - index));
-		memcpy(data + index, items, sizeof(T) * itemsCount);
+		if (itemsCount != 0) memcpy(data + index, items, sizeof(T) * itemsCount);
 		count += itemsCount;
 	}
 
@@ -242,7 +242,7 @@
 	{
 		fb_assert(count <= FB_MAX_SIZEOF - itemsCount);
 		ensureCapacity(count + itemsCount);
-		memcpy(data + count, items, sizeof(T) * itemsCount);
+		if (itemsCount != 0) memcpy(data + count, items, sizeof(T) * itemsCount);
 		count += itemsCount;
 	}
 
@@ -294,7 +294,7 @@
 	{
 		fb_assert(newCount >= count);
 		ensureCapacity(newCount);
-		memset(data + count, 0, sizeof(T) * (newCount - count));
+		if (newCount != count) memset(data + count, 0, sizeof(T) * (newCount - count));
 		count = newCount;
 	}
 
@@ -328,7 +328,7 @@
 	{
 		fb_assert(count <= FB_MAX_SIZEOF - L.count);
 		ensureCapacity(count + L.count);
-		memcpy(data + count, L.data, sizeof(T) * L.count);
+		if (L.count != 0) memcpy(data + count, L.data, sizeof(T) * L.count);
 		count += L.count;
 	}
 
@@ -462,7 +462,7 @@
 
 			T* newdata = static_cast<T*>
 				(this->getPool().allocate(sizeof(T) * newcapacity ALLOC_ARGS));
-			if (preserve)
+			if (preserve && count != 0)
 				memcpy(newdata, data, sizeof(T) * count);
 			freeData();
 			data = newdata;
--- src/common/classes/fb_string.h
+++ src/common/classes/fb_string.h
@@ -674,7 +674,8 @@
 		}
 		StringType& assign(const void* s, size_type n)
 		{
-			memcpy(baseAssign(n), s, n);
+			auto const p = baseAssign(n);
+			if (n != 0) memcpy(p, s, n);
 			return *this;
 		}
 		StringType& assign(const_pointer s)
--- src/common/common.h
+++ src/common/common.h
@@ -1002,6 +1002,5 @@
 }
 
 #undef UCHAR_TYPE
-#define UCHAR_TYPE uint16_t
 
 #endif /* COMMON_COMMON_H */
--- src/common/unicode_util.cpp
+++ src/common/unicode_util.cpp
@@ -187,7 +187,7 @@
 	Mutex ciAiTransCacheMutex;
 	Array<UTransliterator*> ciAiTransCache;
 
-	void (U_EXPORT2 *uVersionToString)(UVersionInfo versionArray, char* versionString);
+	void (U_EXPORT2 *uVersionToString)(UVersionInfo const versionArray, char* versionString);
 
 	int32_t (U_EXPORT2 *ulocCountAvailable)();
 	const char* (U_EXPORT2 *ulocGetAvailable)(int32_t n);
--- src/dsql/StmtNodes.cpp
+++ src/dsql/StmtNodes.cpp
@@ -6643,7 +6643,7 @@
 
 void StoreNode::genBlr(DsqlCompilerScratch* dsqlScratch)
 {
-	const dsql_msg* message = dsqlGenDmlHeader(dsqlScratch, dsqlRse->as<RseNode>());
+	const dsql_msg* message = dsqlGenDmlHeader(dsqlScratch, dsqlRse == nullptr ? nullptr : dsqlRse->as<RseNode>());
 
 	dsqlScratch->appendUChar(statement2 ? blr_store2 : blr_store);
 	GEN_expr(dsqlScratch, dsqlRelation);
--- src/gpre/hsh.cpp
+++ src/gpre/hsh.cpp
@@ -232,7 +232,7 @@
 {
 	SCHAR c;
 
-	SLONG value = 0;
+	ULONG value = 0;
 
 	while (c = *string++)
 		value = (value << 1) + UPPER(c);
--- src/jrd/GlobalRWLock.cpp
+++ src/jrd/GlobalRWLock.cpp
@@ -78,7 +78,7 @@
 
 	cachedLock = FB_NEW_RPT(getPool(), lockLen)
 		Lock(tdbb, lockLen, lckType, this, lockCaching ? blocking_ast_cached_lock : NULL);
-	memcpy(cachedLock->getKeyString(), lockStr, lockLen);
+	if (lockLen != 0) memcpy(cachedLock->getKeyString(), lockStr, lockLen);
 }
 
 GlobalRWLock::~GlobalRWLock()
--- src/jrd/Optimizer.cpp
+++ src/jrd/Optimizer.cpp
@@ -368,7 +368,7 @@
 
 	// Allocate needed indexScratches
 
-	index_desc* idx = csb_tail->csb_idx->items;
+	index_desc* idx = csb_tail->csb_idx == nullptr ? nullptr : csb_tail->csb_idx->items;
 	for (int i = 0; i < csb_tail->csb_indices; ++i, ++idx)
 		indexScratches.add(IndexScratch(p, tdbb, idx, csb_tail));
 }
--- src/jrd/blb.cpp
+++ src/jrd/blb.cpp
@@ -1786,7 +1786,7 @@
 	arg.slice_base = array->arr_data;
 
 	SLONG variables[64];
-	memcpy(variables, param, MIN(sizeof(variables), param_length));
+	if (param_length != 0) memcpy(variables, param, MIN(sizeof(variables), param_length));
 
 	if (SDL_walk(tdbb->tdbb_status_vector, sdl, array->arr_data, &array_desc->arr_desc,
 				 variables, slice_callback, &arg))
--- src/jrd/btn.cpp
+++ src/jrd/btn.cpp
@@ -387,7 +387,7 @@
 
 	put_short(pagePointer, offset);
 	pagePointer += sizeof(USHORT);
-	memmove(pagePointer, data, length);
+	if (length != 0) memmove(pagePointer, data, length);
 	pagePointer += length;
 	return pagePointer;
 }
@@ -622,7 +622,7 @@
 	}
 
 	// Store data
-	if (withData) {
+	if (withData && length != 0) {
 		memcpy(pagePointer, data, length);
 	}
 	pagePointer += length;
--- src/jrd/btr.cpp
+++ src/jrd/btr.cpp
@@ -5206,7 +5206,7 @@
 			// Push node on end in list
 			jumpNodes->add(jumpNode);
 			// Store new data in jumpKey, so a new jump node can calculate prefix
-			memcpy(jumpData + jumpNode.prefix, jumpNode.data, jumpNode.length);
+			if (jumpNode.length != 0) memcpy(jumpData + jumpNode.prefix, jumpNode.data, jumpNode.length);
 			jumpLength = jumpNode.length + jumpNode.prefix;
 
 			// Check if this could be our split point (if we need to split)
@@ -5391,7 +5391,7 @@
 	// First, store needed data for beforeInsertNode into tempData.
 	HalfStaticArray<UCHAR, MAX_KEY> tempBuf;
 	UCHAR* tempData = tempBuf.getBuffer(newLength);
-	memcpy(tempData, beforeInsertNode.data + newPrefix - beforeInsertNode.prefix, newLength);
+	if (newLength != 0) memcpy(tempData, beforeInsertNode.data + newPrefix - beforeInsertNode.prefix, newLength);
 
 	beforeInsertNode.prefix = newPrefix;
 	beforeInsertNode.length = newLength;
@@ -5611,7 +5611,7 @@
 			for (size_t i = 0; i < jumpNodes->getCount(); i++, index++)
 			{
 				UCHAR* q = new_key->key_data + walkJumpNode[i].prefix;
-				memcpy(q, walkJumpNode[i].data, walkJumpNode[i].length);
+				if (walkJumpNode[i].length != 0) memcpy(q, walkJumpNode[i].data, walkJumpNode[i].length);
 				if (index == splitJumpNodeIndex)
 				{
 					jn = &walkJumpNode[i];
@@ -5636,7 +5636,7 @@
 					const USHORT length = walkJumpNode[i].prefix + walkJumpNode[i].length;
 					UCHAR* newData = FB_NEW_POOL(*tdbb->getDefaultPool()) UCHAR[length];
 					memcpy(newData, new_key->key_data, walkJumpNode[i].prefix);
-					memcpy(newData + walkJumpNode[i].prefix, walkJumpNode[i].data,
+					if (walkJumpNode[i].length != 0) memcpy(newData + walkJumpNode[i].prefix, walkJumpNode[i].data,
 						walkJumpNode[i].length);
 					delete[] walkJumpNode[i].data;
 					walkJumpNode[i].prefix = 0;
--- src/jrd/evl.cpp
+++ src/jrd/evl.cpp
@@ -415,7 +415,7 @@
 	case dtype_real:
 	case dtype_sql_time:
 	case dtype_sql_date:
-		value->vlu_misc.vlu_long = *((SLONG*) from.dsc_address);
+		memcpy(&value->vlu_misc.vlu_long, from.dsc_address, sizeof (SLONG));
 		return;
 
 	case dtype_int64:
--- src/jrd/lck.cpp
+++ src/jrd/lck.cpp
@@ -488,7 +488,7 @@
 		break;
 	}
 
-	dbb->dbb_lock_mgr->shutdownOwner(tdbb, owner_handle_ptr);
+	LockManager::shutdownOwner(dbb->dbb_lock_mgr, tdbb, owner_handle_ptr);
 }
 
 
--- src/lock/lock.cpp
+++ src/lock/lock.cpp
@@ -441,7 +441,7 @@
 }
 
 
-void LockManager::shutdownOwner(thread_db* tdbb, SRQ_PTR* owner_handle)
+void LockManager::shutdownOwner(LockManager* This, thread_db* tdbb, SRQ_PTR* owner_handle)
 {
 /**************************************
  *
@@ -460,8 +460,9 @@
 	if (!owner_offset)
 		return;
 
-	LockTableGuard guard(this, FB_FUNCTION, owner_offset);
+	LockTableGuard guard(This, FB_FUNCTION, owner_offset);
 
+#define SRQ_BASE                    ((UCHAR*) This->m_sharedMemory->getHeader())
 	own* owner = (own*) SRQ_ABS_PTR(owner_offset);
 	if (!owner->own_count)
 		return;
@@ -472,7 +473,7 @@
 	while (owner->own_ast_count)
 	{
 		{ // checkout scope
-			LockTableCheckout checkout(this, FB_FUNCTION);
+			LockTableCheckout checkout(This, FB_FUNCTION);
 			EngineCheckout cout(tdbb, FB_FUNCTION, true);
 			Thread::sleep(10);
 		}
@@ -484,8 +485,9 @@
 	// released before destroying the lock owner. This is not strictly required,
 	// but it enforces the proper object lifetime discipline through the codebase.
 	fb_assert(SRQ_EMPTY(owner->own_requests));
+#define SRQ_BASE                    ((UCHAR*) m_sharedMemory->getHeader())
 
-	purge_owner(owner_offset, owner);
+	This->purge_owner(owner_offset, owner);
 
 	*owner_handle = 0;
 }
--- src/lock/lock_proto.h
+++ src/lock/lock_proto.h
@@ -402,7 +402,7 @@
 	static void destroy(LockManager*);
 
 	bool initializeOwner(Firebird::CheckStatusWrapper*, LOCK_OWNER_T, UCHAR, SRQ_PTR*);
-	void shutdownOwner(thread_db*, SRQ_PTR*);
+	static void shutdownOwner(LockManager* This, thread_db*, SRQ_PTR*);
 
 	SRQ_PTR enqueue(thread_db*, Firebird::CheckStatusWrapper*, SRQ_PTR, const USHORT,
 		const UCHAR*, const USHORT, UCHAR, lock_ast_t, void*, SINT64, SSHORT, SRQ_PTR);
--- src/yvalve/gds.cpp
+++ src/yvalve/gds.cpp
@@ -2561,7 +2561,7 @@
 		value += ((SLONG) *ptr++) << shift;
 		shift += 8;
 	}
-	value += ((SLONG)(SCHAR) *ptr) << shift;
+	value += ((ULONG)(SCHAR) *ptr) << shift;
 
 	return value;
 }