mirror of
https://github.com/transmission/transmission
synced 2025-02-03 04:53:27 +00:00
fix terribly nasty bencode corruption bug from r2024 regarding the sorting of dictionary keys in tr_bencDictAdd(). this corrupts all the pointers that are already floating out there to existing values in the dictionary... if BitTornado really needs these to be sorted, then we should sort a temporary copy in tr_bencSave(), not here in our internal structures.
This commit is contained in:
parent
64ce2edbfb
commit
5128d0a434
1 changed files with 3 additions and 15 deletions
|
@ -365,26 +365,14 @@ benc_val_t * tr_bencListAdd( benc_val_t * list )
|
|||
benc_val_t * tr_bencDictAdd( benc_val_t * dict, const char * key )
|
||||
{
|
||||
benc_val_t * keyval, * itemval;
|
||||
int i;
|
||||
|
||||
assert( TYPE_DICT == dict->type );
|
||||
assert( dict->val.l.count + 2 <= dict->val.l.alloc );
|
||||
|
||||
/* Keep dictionaries sorted by keys alphabetically.
|
||||
BitTornado-based clients (and maybe others) need this. */
|
||||
for( i = 0; i < dict->val.l.count; i += 2 )
|
||||
{
|
||||
assert( TYPE_STR == dict->val.l.vals[i].type );
|
||||
if( strcmp( key, dict->val.l.vals[i].val.s.s ) < 0 )
|
||||
break;
|
||||
}
|
||||
memmove( &dict->val.l.vals[i+2], &dict->val.l.vals[i],
|
||||
( dict->val.l.count - i ) * sizeof(benc_val_t) );
|
||||
keyval = &dict->val.l.vals[i];
|
||||
itemval = &dict->val.l.vals[i+1];
|
||||
dict->val.l.count += 2;
|
||||
|
||||
keyval = dict->val.l.vals + dict->val.l.count++;
|
||||
tr_bencInitStr( keyval, key, -1, 1 );
|
||||
|
||||
itemval = dict->val.l.vals + dict->val.l.count++;
|
||||
tr_bencInit( itemval, TYPE_INT );
|
||||
|
||||
return itemval;
|
||||
|
|
Loading…
Reference in a new issue