Changeset 41

Show
Ignore:
Timestamp:
05/18/07 17:28:15 (2 years ago)
Author:
csellers
Message:

Added overflow check for handling array of failure times

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RHEL5/pam_tally2/pam_tally.c

    r40 r41  
    516516               lock_time applies */ 
    517517            tally->fail_cnt = oldcnt; 
    518             /* TODO check for out of fail_time bounds */ 
    519             tally->fail_time[oldcnt] = 0; 
     518            tally->fail_time[(oldcnt>TALLYLOG_FAIL_TIME_COUNT) ? 
     519                              TALLYLOG_FAIL_TIME_COUNT-1 : 
     520                              oldcnt-1] = 0; 
    520521 
    521522            if (!(opts->ctrl & OPT_QUIET)) { 
     
    566567    /* to remember old fail time (for locktime) */ 
    567568    if (oldtime && tally.fail_cnt > 0) { 
    568         /* TODO check for out of fail_time bounds */ 
    569         *oldtime = (time_t)tally.fail_time[tally.fail_cnt-1]; 
     569        *oldtime = (time_t)tally.fail_time[ 
     570                (tally.fail_cnt>TALLYLOG_FAIL_TIME_COUNT) ? 
     571                TALLYLOG_FAIL_TIME_COUNT-1 : 
     572                tally.fail_cnt-1]; 
    570573    } 
    571574     
    572     /* TODO check for out of fail_time bounds */ 
    573     tally.fail_time[tally.fail_cnt] = time(NULL); 
     575    tally.fail_time[(tally.fail_cnt>=TALLYLOG_FAIL_TIME_COUNT) ? 
     576                TALLYLOG_FAIL_TIME_COUNT-1 : 
     577                tally.fail_cnt] = time(NULL); 
    574578 
    575579    (void) pam_get_item(pamh, PAM_RHOST, &remote_host); 
     
    823827 
    824828   pwent = getpwuid(uid); 
    825    /* TODO check for out of fail_time bounds */ 
    826    fail_time = tally->fail_time[tally->fail_cnt-1]; 
     829   fail_time = tally->fail_time[ 
     830                (tally->fail_cnt>TALLYLOG_FAIL_TIME_COUNT) ? 
     831                TALLYLOG_FAIL_TIME_COUNT-1 : 
     832                tally->fail_cnt-1]; 
    827833   tm = localtime(&fail_time); 
    828834   strftime (ptime, sizeof (ptime), "%D %H:%M:%S", tm); 
  • trunk/RHEL5/pam_tally2/tallylog.h

    r40 r41  
    3939#ifndef _TALLYLOG_H 
    4040#define _TALLYLOG_H 
     41#define TALLYLOG_FAIL_TIME_COUNT 9 
    4142 
    4243#include <stdint.h> 
     
    4647        uint16_t        reserved;       /* reserved for future use */ 
    4748        uint16_t        fail_cnt;       /* failures since last success */ 
    48         uint64_t        fail_time[9]; /* time of previous failures */ 
     49        uint64_t        fail_time[TALLYLOG_FAIL_TIME_COUNT];  /* time of previous failures */ 
    4950}; 
    5051/* 64 bytes / entry */