fix append to uninitialized buffer in FlatIndex::created
The long_name variable is not initialized. When the append_oname
function is called, it will strlen(long_name) and get a result
that depends on the stack content. The long_name is truncated to a
zero length string to prevent this unexpected behavior.
There is no sure way to trigger the problem by writing a unit
test. Unit tests are added for all public methods of the FlatIndex
class. Most of the time the tests fail if the long_name variable is
not properly initialized.
* uint32_t collection_version()
* coll_t coll() const
* void set_ref(std::tr1::shared_ptr<CollectionIndex> ref)
* int cleanup()
* int init()
* int created(const hobject_t &hoid, const char *path)
* int unlink(const hobject_t &hoid)
* int lookup(const hobject_t &hoid, IndexedPath *path, int *exist)
* int collection_list(vector<hobject_t> *ls)
* int collection_list_partial(const hobject_t &start, int min_count, int max_count, snapid_t seq, vector<hobject_t> *ls, hobject_t *next)
There are a number of border cases that cannot be tested, such as the
logic of the lfn_get static function. Since FlatIndex code is designed
to transition from older namespace conventions, it is difficult to
figure out.
The tests rely on xattr(2) and their availability is checked before
running them.