Changeset 1731

Show
Ignore:
Timestamp:
04/09/2007 07:58:57 PM (17 months ago)
Author:
jan
Message:

- fixed various crashes at startup on broken accesslog.format strings

(fixes #1000)

- fixed handling of %% in accesslog.format

Location:
branches/lighttpd-1.4.x
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/lighttpd-1.4.x/NEWS

    r1730 r1731  
    2929  * fixed accesslog.use-syslog in a conditional and the caching of the 
    3030    accesslog for files (fixes #1064) 
     31  * fixed various crashes at startup on broken accesslog.format strings (#1000) 
     32  * fixed handling of %% in accesslog.format  
    3133 
    3234 
  • branches/lighttpd-1.4.x/src/mod_accesslog.c

    r1729 r1731  
    160160        size_t i, j, k = 0, start = 0; 
    161161 
     162        if (format->used == 0) return -1; 
     163 
    162164        for (i = 0; i < format->used - 1; i++) { 
    163  
    164165                switch(format->ptr[i]) { 
    165166                case '%': 
    166                         if (start != i) { 
    167                                 /* copy the string */ 
     167                        if (i > 0 && start != i) { 
     168                                /* copy the string before this % */ 
    168169                                if (fields->size == 0) { 
    169170                                        fields->size = 16; 
     
    184185                        } 
    185186 
    186  
    187187                        /* we need a new field */ 
    188188 
     
    200200                        case '>': 
    201201                        case '<': 
    202                                 /* only for s */ 
     202                                /* after the } has to be a character */ 
     203                                if (format->ptr[i+2] == '\0') { 
     204                                        log_error_write(srv, __FILE__, __LINE__, "s", "%< and %> have to be followed by a format-specifier"); 
     205                                        return -1; 
     206                                } 
     207 
    203208 
    204209                                for (j = 0; fmap[j].key != '\0'; j++) { 
     
    218223 
    219224                                if (fmap[j].key == '\0') { 
    220                                         log_error_write(srv, __FILE__, __LINE__, "ss", "config: ", "failed"); 
     225                                        log_error_write(srv, __FILE__, __LINE__, "s", "%< and %> have to be followed by a valid format-specifier"); 
    221226                                        return -1; 
    222227                                } 
    223228 
    224229                                start = i + 3; 
     230                                i = start - 1; /* skip the string */ 
    225231 
    226232                                break; 
     
    233239 
    234240                                if (k == format->used - 1) { 
    235                                         log_error_write(srv, __FILE__, __LINE__, "ss", "config: ", "failed"); 
     241                                        log_error_write(srv, __FILE__, __LINE__, "s", "%{ has to be terminated by a }"); 
    236242                                        return -1; 
    237243                                } 
     244 
     245                                /* after the } has to be a character */ 
    238246                                if (format->ptr[k+1] == '\0') { 
    239                                         log_error_write(srv, __FILE__, __LINE__, "ss", "config: ", "failed"); 
     247                                        log_error_write(srv, __FILE__, __LINE__, "s", "%{...} has to be followed by a format-specifier"); 
     248                                        return -1; 
     249                                } 
     250 
     251                                if (k == i + 2) { 
     252                                        log_error_write(srv, __FILE__, __LINE__, "s", "%{...} has to be contain a string"); 
    240253                                        return -1; 
    241254                                } 
     
    259272 
    260273                                if (fmap[j].key == '\0') { 
    261                                         log_error_write(srv, __FILE__, __LINE__, "ss", "config: ", "failed"); 
     274                                        log_error_write(srv, __FILE__, __LINE__, "s", "%{...} has to be followed by a valid format-specifier"); 
    262275                                        return -1; 
    263276                                } 
    264277 
    265278                                start = k + 2; 
     279                                i = start - 1; /* skip the string */ 
    266280 
    267281                                break; 
    268282                        default: 
     283                                /* after the % has to be a character */ 
     284                                if (format->ptr[i+1] == '\0') { 
     285                                        log_error_write(srv, __FILE__, __LINE__, "s", "% has to be followed by a format-specifier"); 
     286                                        return -1; 
     287                                } 
     288 
    269289                                for (j = 0; fmap[j].key != '\0'; j++) { 
    270290                                        if (fmap[j].key != format->ptr[i+1]) continue; 
     
    283303 
    284304                                if (fmap[j].key == '\0') { 
    285                                         log_error_write(srv, __FILE__, __LINE__, "ss", "config: ", "failed"); 
     305                                        log_error_write(srv, __FILE__, __LINE__, "s", "% has to be followed by a valid format-specifier"); 
    286306                                        return -1; 
    287307                                } 
    288308 
    289309                                start = i + 2; 
     310                                i = start - 1; /* skip the string */ 
    290311 
    291312                                break; 
     
    782803                                buffer_append_string(b, get_http_method_name(con->request.http_method)); 
    783804                                break; 
     805                        case FORMAT_PERCENT: 
     806                                buffer_append_string(b, "%"); 
     807                                break; 
    784808                        case FORMAT_SERVER_PORT: 
    785809                                buffer_append_long(b, srv->srvconf.port);