output = input;
/* first create a match string which always has a trailing slash */
- l = ap_cpystrn(matchbuf, match, sizeof(matchbuf)) - matchbuf;
- if (matchbuf[l-1] != '/') {
+ l = ap_cpystrn(matchbuf, match, sizeof(matchbuf) - 1) - matchbuf;
+ if (!l || matchbuf[l-1] != '/') {
matchbuf[l] = '/';
matchbuf[l+1] = '\0';
l++;
output = ap_pstrdup(r->pool, output+l);
/* and now add the base-URL as replacement prefix */
- l = ap_cpystrn(substbuf, subst, sizeof(substbuf)) - substbuf;
- if (substbuf[l-1] != '/') {
+ l = ap_cpystrn(substbuf, subst, sizeof(substbuf) - 1) - substbuf;
+ if (!l || substbuf[l-1] != '/') {
substbuf[l] = '/';
substbuf[l+1] = '\0';
l++;