Hi
While browsing the smtpd(8) source I discovered that makemap(8) uses
strsep(3) to split the alias lines at commas. This is different from
other code which uses expand_line (which uses expand_line_split). This
leads to contrived alias lines such as
martin: "/usr/local/bin/weird_mda abc,def", alias2
to fail, because it splits at the comma in double quotes and then fails
in text_to_expandnode. smtpd(8) on the other hand is fine with the
alias file. Probably an example working with makemap(8) but not
smtpd(8) can be found as well. I think makemap(8) should accept the
same as the other code so I made the make_aliases function more similar
to expand_line. I am not calling expand_line directly to avoid needing
to handle a struct expand around. So expand_line_split has to be
public. With the changes the text argument to make_aliases can be
const.
I only tested with the alias config in base and my contrived example
lines.
What do you think? Is it a problem makemap(8) only works with lines of
less than LINE_MAX now?
Thanks!
Best,
Martin
diff 36c339f786087486bbdf963db577d740fedf8e93
blob - 99b25d51f5e35902fe1fe2fb25f16c008d389f58
file + expand.c
--- expand.c
+++ expand.c
@@ -185,7 +185,7 @@ expand_cmp(struct expandnode *e1, struct expandnode *e
return (0);
}
-static int
+int
expand_line_split(char **line, char **ret)
{
static char buffer[LINE_MAX];
blob - e2a9e465b13bb4b93c69fa45ff397ea16bfd998b
file + makemap.c
--- makemap.c
+++ makemap.c
@@ -49,7 +49,7 @@ static int parse_entry(DB *, int *, char *, size_t, s
static int parse_mapentry(DB *, int *, char *, size_t, size_t);
static int parse_setentry(DB *, int *, char *, size_t, size_t);
static int make_plain(DBT *, char *);
-static int make_aliases(DBT *, char *);
+static int make_aliases(DBT *, const char *);
static char *conf_aliases(char *);
static int dump_db(const char *, DBTYPE);
@@ -407,35 +407,36 @@ make_plain(DBT *val, char *text)
}
static int
-make_aliases(DBT *val, char *text)
+make_aliases(DBT *val, const char *text)
{
struct expandnode xn;
- char *subrcpt;
- char *origtext;
+ char buffer[LINE_MAX];
+ char *p, *subrcpt;
+ int ret;
val->data = NULL;
val->size = 0;
- origtext = xstrdup(text);
+ memset(buffer, 0, sizeof buffer);
+ if (strlcpy(buffer, text, sizeof buffer) >= sizeof buffer)
+ return 0;
- while ((subrcpt = strsep(&text, ",")) != NULL) {
- /* subrcpt: strip initial and trailing whitespace. */
+ p = buffer;
+ while ((ret = expand_line_split(&p, &subrcpt)) > 0) {
subrcpt = strip(subrcpt);
- if (*subrcpt == '\0')
- goto error;
-
+ if (subrcpt[0] == '\0')
+ continue;
if (!text_to_expandnode(&xn, subrcpt))
- goto error;
+ return 0;
}
+
+ /* expand_line_split() returned < 0 */
+ if (ret < 0)
+ return 0;
- val->data = origtext;
- val->size = strlen(origtext) + 1;
+ val->data = xstrdup(text);
+ val->size = strlen(text) + 1;
return (val->size);
-
-error:
- free(origtext);
-
- return 0;
}
static char *
blob - 487573da170bed884e34b15f85142110d28897b5
file + smtpd.h
--- smtpd.h
+++ smtpd.h
@@ -1338,6 +1338,7 @@ void expand_insert(struct expand *, struct expandnode
struct expandnode *expand_lookup(struct expand *, struct expandnode *);
void expand_clear(struct expand *);
void expand_free(struct expand *);
+int expand_line_split(char **, char **);
int expand_line(struct expand *, const char *, int);
int expand_to_text(struct expand *, char *, size_t);
RB_PROTOTYPE(expandtree, expandnode, nodes, expand_cmp);