summaryrefslogtreecommitdiff
blob: e252bab568b1bf85c89611842257d1ac9053b499 (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
Author: Fabian Fagerholm <fabbe@debian.org>
Description: Make sasl_set_alloc a one-time function.
This patch will divert all allocations to whomever called
sasl_set_alloc first, hopefully that will be the application. If
not, we sure *hope* the library doing stupid things has sane
sasl_set_alloc semantics...
It will also deny any futher tries to sasl_set_alloc after one
of the _init functions are called.
This patch was introduced and works fine in SASL 1.5, and no
applications started behaving in insane ways, so chances are it
will also work with SASL 2.1
Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=139568
Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=274087
Reference: https://bugzilla.andrew.cmu.edu/show_bug.cgi?id=2525
--- trunk.orig/lib/client.c
+++ trunk/lib/client.c
@@ -202,6 +202,9 @@
       { NULL, NULL }
   };
 
+  /* lock allocation type */
+  _sasl_allocation_locked++;
+  
   if(_sasl_client_active) {
       /* We're already active, just increase our refcount */
       /* xxx do something with the callback structure? */
--- trunk.orig/lib/common.c
+++ trunk/lib/common.c
@@ -107,6 +107,7 @@
   (sasl_realloc_t *) &realloc,
   (sasl_free_t *) &free
 };
+int _sasl_allocation_locked = 0;
 
 #define SASL_ENCODEV_EXTRA  4096
 
@@ -637,6 +638,8 @@
 	       sasl_realloc_t *r,
 	       sasl_free_t *f)
 {
+  if (_sasl_allocation_locked++)  return;
+
   _sasl_allocation_utils.malloc=m;
   _sasl_allocation_utils.calloc=c;
   _sasl_allocation_utils.realloc=r;
--- trunk.orig/lib/saslint.h
+++ trunk/lib/saslint.h
@@ -300,6 +300,7 @@
 
 extern sasl_allocation_utils_t _sasl_allocation_utils;
 extern sasl_mutex_utils_t _sasl_mutex_utils;
+extern int _sasl_allocation_locked;
 
 /*
  * checkpw.c
--- trunk.orig/lib/server.c
+++ trunk/lib/server.c
@@ -698,6 +698,9 @@
 	{ NULL, NULL }
     };
 
+    /* lock allocation type */
+    _sasl_allocation_locked++;
+
     /* we require the appname (if present) to be short enough to be a path */
     if (appname != NULL && strlen(appname) >= PATH_MAX)
 	return SASL_BADPARAM;