dovecot-2.2: var_expand*(): Don't use a data stack frame when ex...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Jan 5 01:14:34 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/3a33e686fc38
changeset: 15509:3a33e686fc38
user: Timo Sirainen <tss at iki.fi>
date: Wed Nov 07 17:37:16 2012 +0200
description:
var_expand*(): Don't use a data stack frame when expanding long %{variables}
This avoids potential crashes if the destination string is also allocated
from data stack and requires growing.
diffstat:
src/lib/var-expand.c | 50 ++++++++++++++++++++++++--------------------------
1 files changed, 24 insertions(+), 26 deletions(-)
diffs (71 lines):
diff -r 6c1b4b9f527c -r 3a33e686fc38 src/lib/var-expand.c
--- a/src/lib/var-expand.c Wed Nov 07 17:05:47 2012 +0200
+++ b/src/lib/var-expand.c Wed Nov 07 17:37:16 2012 +0200
@@ -160,7 +160,7 @@
const void *key_start, unsigned int key_len, void *context)
{
const struct var_expand_table *t;
- const char *value = NULL;
+ const char *key, *value = NULL;
if (table != NULL) {
for (t = table; !TABLE_LAST(t); t++) {
@@ -171,35 +171,33 @@
}
}
}
+ key = t_strndup(key_start, key_len);
/* built-in variables: */
- T_BEGIN {
- const char *key = t_strndup(key_start, key_len);
+ switch (key_len) {
+ case 3:
+ if (strcmp(key, "pid") == 0)
+ value = my_pid;
+ else if (strcmp(key, "uid") == 0)
+ value = dec2str(geteuid());
+ else if (strcmp(key, "gid") == 0)
+ value = dec2str(getegid());
+ break;
+ case 8:
+ if (strcmp(key, "hostname") == 0)
+ value = my_hostname;
+ break;
+ }
- switch (key_len) {
- case 3:
- if (strcmp(key, "pid") == 0)
- value = my_pid;
- else if (strcmp(key, "uid") == 0)
- value = dec2str(geteuid());
- else if (strcmp(key, "gid") == 0)
- value = dec2str(getegid());
- break;
- case 8:
- if (strcmp(key, "hostname") == 0)
- value = my_hostname;
- break;
- }
- if (value == NULL) {
- const char *data = strchr(key, ':');
+ if (value == NULL) {
+ const char *data = strchr(key, ':');
- if (data != NULL)
- key = t_strdup_until(key, data++);
- else
- data = "";
- value = var_expand_func(func_table, key, data, context);
- }
- } T_END;
+ if (data != NULL)
+ key = t_strdup_until(key, data++);
+ else
+ data = "";
+ value = var_expand_func(func_table, key, data, context);
+ }
return value;
}
More information about the dovecot-cvs
mailing list