mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-14 20:33:48 +00:00
Fixed crash with strlcpy when source and destination overlap
This commit is contained in:
parent
7ba39510b7
commit
4383792969
12
src/elogd.c
12
src/elogd.c
@ -18616,7 +18616,7 @@ char *param_in_str(char *str, char *param)
|
|||||||
BOOL subst_param(char *str, int size, char *param, char *value)
|
BOOL subst_param(char *str, int size, char *param, char *value)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *p1, *p2, *s, param_enc[256];
|
char *p1, *p2, *s, param_enc[256], str2[256];
|
||||||
|
|
||||||
strlcpy(param_enc, param, sizeof(param_enc));
|
strlcpy(param_enc, param, sizeof(param_enc));
|
||||||
url_slash_encode(param_enc, sizeof(param_enc));
|
url_slash_encode(param_enc, sizeof(param_enc));
|
||||||
@ -18658,14 +18658,16 @@ BOOL subst_param(char *str, int size, char *param, char *value)
|
|||||||
len = p2 - p1;
|
len = p2 - p1;
|
||||||
if (len > (int) strlen(value)) {
|
if (len > (int) strlen(value)) {
|
||||||
/* new value is shorter than old one */
|
/* new value is shorter than old one */
|
||||||
strlcpy(p1, value, size - (p1 - str));
|
strlcpy(str2, value, size - (p1 - str));
|
||||||
strlcpy(p1 + strlen(value), p2, size - (p1 + strlen(value) - str));
|
strlcpy(str2 + strlen(value), p2, size - (p1 + strlen(value) - str));
|
||||||
|
strlcpy(p1, str2, size - (p1 - str));
|
||||||
} else {
|
} else {
|
||||||
/* new value is longer than old one */
|
/* new value is longer than old one */
|
||||||
s = (char *) xmalloc(size);
|
s = (char *) xmalloc(size);
|
||||||
strlcpy(s, p2, size);
|
strlcpy(s, p2, size);
|
||||||
strlcpy(p1, value, size - (p1 - str));
|
strlcpy(str2, value, size - (p1 - str));
|
||||||
strlcat(p1, s, size - (p1 + strlen(value) - str));
|
strlcat(str2, s, size - (p1 + strlen(value) - str));
|
||||||
|
strlcpy(p1, str2, size - (p1 - str));
|
||||||
xfree(s);
|
xfree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user