mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
BUG/MINOR: log: fix minor resource leaks on logformat error path
As reported by Ilya in issue #392, Coverity found that we're leaking allocated strings on error paths in parse_logformat(). Let's use a proper exit label for failures instead of seeding return 0 everywhere. This should be backported to all supported versions.
This commit is contained in:
parent
9ef75ecea1
commit
51013e82d4
15
src/log.c
15
src/log.c
@ -618,7 +618,7 @@ int parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
|
|||||||
sp = str - 1; /* send both the '%' and the current char */
|
sp = str - 1; /* send both the '%' and the current char */
|
||||||
memprintf(err, "unexpected variable name near '%c' at position %d line : '%s'. Maybe you want to write a single '%%', use the syntax '%%%%'",
|
memprintf(err, "unexpected variable name near '%c' at position %d line : '%s'. Maybe you want to write a single '%%', use the syntax '%%%%'",
|
||||||
*str, (int)(str - backfmt), fmt);
|
*str, (int)(str - backfmt), fmt);
|
||||||
return 0;
|
goto fail;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -645,7 +645,7 @@ int parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memprintf(err, "parse argument modifier without variable name near '%%{%s}'", arg);
|
memprintf(err, "parse argument modifier without variable name near '%%{%s}'", arg);
|
||||||
return 0;
|
goto fail;
|
||||||
|
|
||||||
case LF_STEXPR: // text immediately following '%['
|
case LF_STEXPR: // text immediately following '%['
|
||||||
if (*str == ']') { // end of arg
|
if (*str == ']') { // end of arg
|
||||||
@ -678,16 +678,16 @@ int parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
|
|||||||
switch (pformat) {
|
switch (pformat) {
|
||||||
case LF_VAR:
|
case LF_VAR:
|
||||||
if (!parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options, err))
|
if (!parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options, err))
|
||||||
return 0;
|
goto fail;
|
||||||
break;
|
break;
|
||||||
case LF_STEXPR:
|
case LF_STEXPR:
|
||||||
if (!add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap, err))
|
if (!add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap, err))
|
||||||
return 0;
|
goto fail;
|
||||||
break;
|
break;
|
||||||
case LF_TEXT:
|
case LF_TEXT:
|
||||||
case LF_SEPARATOR:
|
case LF_SEPARATOR:
|
||||||
if (!add_to_logformat_list(sp, str, pformat, list_format, err))
|
if (!add_to_logformat_list(sp, str, pformat, list_format, err))
|
||||||
return 0;
|
goto fail;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sp = str; /* new start of text at every state switch and at every separator */
|
sp = str; /* new start of text at every state switch and at every separator */
|
||||||
@ -696,11 +696,14 @@ int parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
|
|||||||
|
|
||||||
if (pformat == LF_STARTVAR || pformat == LF_STARG || pformat == LF_STEXPR) {
|
if (pformat == LF_STARTVAR || pformat == LF_STARG || pformat == LF_STEXPR) {
|
||||||
memprintf(err, "truncated line after '%s'", var ? var : arg ? arg : "%");
|
memprintf(err, "truncated line after '%s'", var ? var : arg ? arg : "%");
|
||||||
return 0;
|
goto fail;
|
||||||
}
|
}
|
||||||
free(backfmt);
|
free(backfmt);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
fail:
|
||||||
|
free(backfmt);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user