Skip to content

Commit 86ae8e8

Browse files
committed
feat: reject padded reward owner metadata
1 parent 8a88d25 commit 86ae8e8

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

internal/minimal/shared_world.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ func (r *sharedWorldRegistry) RegisterGroundGold(ownerID uint64, ownerLogin stri
931931
}
932932

933933
func (r *sharedWorldRegistry) registerGroundItem(ownerID uint64, ownerLogin string, character loginticket.Character, vid uint32, item inventory.ItemInstance, goldAmount uint32) bool {
934-
if r == nil || ownerID == 0 || strings.TrimSpace(ownerLogin) == "" || strings.TrimSpace(character.Name) == "" || vid == 0 || item.Vnum == 0 {
934+
if r == nil || ownerID == 0 || ownerLogin == "" || ownerLogin != strings.TrimSpace(ownerLogin) || character.Name == "" || character.Name != strings.TrimSpace(character.Name) || vid == 0 || item.Vnum == 0 {
935935
return false
936936
}
937937

internal/minimal/shared_world_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,27 @@ func TestSharedWorldRegistryRegisterGroundRewardsRejectsBlankOwnerName(t *testin
527527
}
528528
}
529529

530+
func TestSharedWorldRegistryRegisterGroundRewardsRejectsPaddedOwnerMetadata(t *testing.T) {
531+
registry := newSharedWorldRegistry()
532+
owner := peerVisibilityCharacter("PaddedNameRewardOwner", 0x010301a2, 0x020401a2, 1200, 2200, 0, 101, 201)
533+
ownerID, _ := registry.Join(owner, newPendingServerFrames(), nil)
534+
if ownerID == 0 {
535+
t.Fatal("expected padded-metadata reward owner join to allocate a shared-world entity id")
536+
}
537+
538+
paddedNameOwner := owner
539+
paddedNameOwner.Name = " PaddedNameRewardOwner "
540+
if registry.RegisterGroundItem(ownerID, "padded-metadata-owner", paddedNameOwner, 0x07000023, inventory.ItemInstance{Vnum: 3001, Count: 1}) {
541+
t.Fatal("expected padded owner-name ground-item reward registration to fail closed")
542+
}
543+
if registry.RegisterGroundGold(ownerID, " padded-metadata-owner ", owner, 0x07000024, 250) {
544+
t.Fatal("expected padded owner-login ground-gold reward registration to fail closed")
545+
}
546+
if registry.GroundItemExists(0x07000023) || registry.GroundItemExists(0x07000024) {
547+
t.Fatal("expected rejected padded-metadata reward ground entries to stay absent")
548+
}
549+
}
550+
530551
func TestSharedWorldRegistryRegisterGroundRewardsRejectsStaleLiveOwnerSnapshotAfterOwnerDeath(t *testing.T) {
531552
registry := newSharedWorldRegistry()
532553
owner := peerVisibilityCharacter("StaleLiveRewardOwner", 0x01030193, 0x02040193, 1200, 2200, 0, 101, 201)

spec/protocol/non-player-reward-bootstrap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Reward descriptors fail closed when:
5656
- any `reward_drop_vnums` entry is `0`
5757
- any `reward_drop_vnums` entry is duplicated in the same descriptor
5858
- a runtime-generated ground-entry VID for a configured item-shaped or gold-shaped drop would be `0`
59-
- the reward owner login is empty or blank after trimming whitespace when registering a configured item-shaped or gold-shaped drop
60-
- the reward owner character name is empty or blank after trimming whitespace when registering a configured item-shaped or gold-shaped drop
59+
- the reward owner login is empty, blank after trimming whitespace, or padded with leading/trailing whitespace when registering a configured item-shaped or gold-shaped drop
60+
- the reward owner character name is empty, blank after trimming whitespace, or padded with leading/trailing whitespace when registering a configured item-shaped or gold-shaped drop
6161
- a runtime-generated ground-item instance for a configured item-shaped drop would have `vnum = 0`
6262
- a runtime-generated ground-item instance for a configured item-shaped drop would have zero count
6363
- a runtime-generated ground-item instance for a configured item-shaped drop would exceed the current `GC ITEM_GET` count carrier (`255`)

0 commit comments

Comments
 (0)