================
Written by Hallvard B. Furuseth and placed into the public domain.
This software is not subject to any license of the University of Oslo.
================
maildap could address buf[-1] if len was < 2.
REWRITE_SUBMATCH_ESCAPE is '%', not '\'.
librewrite and saslautz could walk past the end of a string which
ended with an escape character.
Hallvard B. Furuseth <h.b.furuseth@usit.uio.no>, April 2002.
continue;
if ( strspn( buf, " \t\n" ) == len )
continue;
- if ( buf[len-2] == '\\' ) {
+ if ( len >= 2 && buf[len-2] == '\\' ) {
pos = len - 2;
room = sizeof(buf) - pos;
continue;
for ( p = string, cnt = 1; p[ 0 ] != '\0' && cnt > 0; p++ ) {
if ( p[ 0 ] == REWRITE_SUBMATCH_ESCAPE ) {
/*
- * '\' marks the beginning of a new map
+ * '%' marks the beginning of a new map
*/
if ( p[ 1 ] == '{' ) {
cnt++;
/*
- * '\' followed by a digit may mark the beginning
+ * '%' followed by a digit may mark the beginning
* of an old map
*/
} else if ( isdigit( (unsigned char) p[ 1 ] ) && p[ 2 ] == '{' ) {
cnt++;
p++;
}
- p++;
+ if ( p[ 1 ] != '\0' )
+ p++;
} else if ( p[ 0 ] == '}' ) {
cnt--;
}
}
for ( begin = p; p[ 0 ] != '\0'; p++ ) {
- if ( p[ 0 ] == '\\' ) {
+ if ( p[ 0 ] == '\\' && p[ 1 ] != '\0' ) {
p++;
} else if ( p[ 0 ] == '\'' || p[ 0 ] == '\"') {
if ( in_quoted_field && p[ 0 ] == quote ) {
for ( p = begin = result, subs_len = 0; p[ 0 ] != '\0'; p++ ) {
/*
- * Keep only single escapes '\'
+ * Keep only single escapes '%'
*/
if ( p[ 0 ] != REWRITE_SUBMATCH_ESCAPE ) {
continue;
reg->sr_offset[0] = -2;
n = 1;
for ( c = reg->sr_replace; *c; c++ ) {
- if ( *c == '\\' ) {
+ if ( *c == '\\' && c[1] ) {
c++;
continue;
}