Changeset 1371

Show
Ignore:
Timestamp:
09/30/08 05:17:21 (5 years ago)
Author:
wichert
Message:

Security: strncpy is not guaranteed to NUL-terminate strings

Location:
trunk/wifidog/libhttpd
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/libhttpd/api.c

    r1368 r1371  
    350350                &addrLen); 
    351351        ipaddr = inet_ntoa(addr.sin_addr); 
    352         if (ipaddr) 
     352        if (ipaddr) { 
    353353                strncpy(r->clientAddr, ipaddr, HTTP_IP_ADDR_LEN); 
    354         else 
     354                r->clientAddr[HTTP_IP_ADDR_LEN-1]=0; 
     355        } else 
    355356                *r->clientAddr = 0; 
    356357        r->readBufRemain = 0; 
     
    439440                        *cp2 = 0; 
    440441                        strncpy(r->request.path,cp,HTTP_MAX_URL); 
     442                        r->request.path[HTTP_MAX_URL-1]=0; 
    441443                        _httpd_sanitiseUrl(r->request.path); 
    442444                        continue; 
     
    508510                                                   r->request.authPassword, 
    509511                                                   cp+1, HTTP_MAX_AUTH); 
     512                                                r->request.authPassword[HTTP_MAX_AUTH-1]=0; 
    510513                                        } 
    511514                                        strncpy(r->request.authUser,  
    512515                                                authBuf, HTTP_MAX_AUTH); 
     516                                        r->request.authUser[HTTP_MAX_AUTH-1]=0; 
    513517                                } 
    514518                        } 
     
    521525                                        strncpy(r->request.referer,cp, 
    522526                                                HTTP_MAX_URL); 
     527                                        r->request.referer[HTTP_MAX_URL-1]=0; 
    523528                                } 
    524529                        } 
     
    533538                                        strncpy(r->request.host,cp, 
    534539                                                HTTP_MAX_URL); 
     540                                        r->request.host[HTTP_MAX_URL-1]=0; 
    535541                                } 
    536542                        } 
     
    544550                                        strncpy(r->request.ifModified,cp, 
    545551                                                HTTP_MAX_URL); 
     552                                        r->request.ifModified[HTTP_MAX_URL-1]=0; 
    546553                                        cp = index(r->request.ifModified, 
    547554                                                ';'); 
     
    557564                                        strncpy(r->request.contentType,cp, 
    558565                                                HTTP_MAX_URL); 
     566                                        r->request.contentType[HTTP_MAX_URL-1]=0; 
    559567                                } 
    560568                        } 
     
    595603                *cp++ = 0; 
    596604                strncpy(r->request.query, cp, sizeof(r->request.query)); 
     605                r->request.query[sizeof(r->request.query)-1]=0; 
    597606                _httpd_storeData(r, cp); 
    598607        } 
     
    642651{ 
    643652        strncpy(server->fileBasePath, path, HTTP_MAX_URL); 
     653        server->fileBasePath[HTTP_MAX_URL-1]=0; 
    644654} 
    645655 
     
    823833{ 
    824834        strncpy(r->response.response, msg, HTTP_MAX_URL); 
     835        r->response.response[HTTP_MAX_URL-1]=0; 
    825836} 
    826837 
     
    945956        r->response.responseLength = 0; 
    946957        strncpy(dirName, httpdRequestPath(r), HTTP_MAX_URL); 
     958        dirName[HTTP_MAX_URL-1]=0; 
    947959        cp = rindex(dirName, '/'); 
    948960        if (cp == NULL) 
     
    952964        } 
    953965        strncpy(entryName, cp + 1, HTTP_MAX_URL); 
     966        entryName[HTTP_MAX_URL-1]=0; 
    954967        if (cp != dirName) 
    955968                *cp = 0; 
  • trunk/wifidog/libhttpd/protocol.c

    r1345 r1371  
    468468 
    469469        strncpy(buffer, dir, HTTP_MAX_URL); 
     470        buffer[HTTP_MAX_URL-1]=0; 
    470471        curItem = server->content; 
    471472        curDir = strtok(buffer,"/");