OpenAFS Master Repository branch, master, updated. openafs-devel-1_9_2-599-g69cbef0

Gerrit Code Review gerrit@openafs.org
Fri, 18 Sep 2026 12:19:50 -0400


The following commit has been merged in the master branch:
commit 69cbef05d4498833362945cb56233704c0a9c756
Author: Andrew Deason <adeason@sinenomine.net>
Date:   Mon Aug 24 11:49:30 2026 -0500

    ptserver: Check for negative eof in listEntries()
    
    Currently, in listEntries() (the implementation for PR_ListEntries()),
    we calculate the max entry index by looking at the cheader.eofPtr value,
    and subtracting the size of the cheader itself.
    
    If the value of cheader.eofPtr is smaller than sizeof(cheader) for any
    reason, then our 'eof' will be negative. We then calculate 'maxentries'
    by dividing the size of a prentry:
    
        maxentries = eof / sizeof(struct prentry);
    
    Here, 'maxentries' and 'eof' are both signed integers, but a sizeof()
    value is an unsigned size_t. So in this division, 'eof' can be
    interpreted as unsigned, and so 'maxentries' will be calculated as a
    large unsigned value.
    
    For example, if the underlying database is completely blank,
    cheader.eofPtr is 0, eof is -65600, and maxentries is calculated as
    1431655423 (at least, on amd64 Linux platforms).
    
    If an administrator runs 'pts listentries -localauth' against a ptserver
    in this situation, 'pts' will try to print out a seemingly-endless list of
    blank entries (presumably around 1.4 billion):
    
        $ pts listentries -localauth
        Name                          ID  Owner Creator
                                       0      0       0
                                       0      0       0
                                       0      0       0
                                       0      0       0
    [...]
    
    This happens because listEntries() will call pr_ReadEntry() for each
    entry we try to read; reading beyond EOF is not an error in ubik, so we
    will successfully read in a blank entry. If the PRTYPE bits in the entry
    are all 0, that indicates a user entry, so we will return the entry to
    the caller if users were requested (the default for 'pts listentries';
    'flag' has PRUSERS set). A blank prentry will of course have all PRTYPE
    bits set to 0, so the prentry will appear to be a user.
    
    Normally, cheader.eofPtr cannot be 0, because Initdb() will detect a
    blank database and initialize the db. But there are some edge cases
    where this can happen, which future commits will address.
    
    For now, make sure this cannot happen by explicitly checking for a
    negative calculated eof. If we do see one, return a PRDBBAD error,
    indicating an error in the database. With this change, now 'pts
    listentries' in this situation will return an error, instead of trying
    to print a large number of blank entries.
    
    Change-Id: Ib59255e2821c1b0cf91f24f6dbdccdb722b5d3b0
    Reviewed-on: https://gerrit.openafs.org/16972
    Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
    Tested-by: BuildBot <buildbot@rampaginggeek.com>
    Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
    Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
    Reviewed-by: Andrew Deason <adeason@sinenomine.net>

 src/ptserver/ptprocs.c | 3 +++
 1 file changed, 3 insertions(+)

-- 
OpenAFS Master Repository