From dab1e966a1af0f62dfb525c57bddf9f10d684bad Mon Sep 17 00:00:00 2001 From: guscarreon Date: Mon, 22 Mar 2021 13:09:24 -0400 Subject: [PATCH] Pubmatic: Fix Shared Memory Overwriting (#1759) --- adapters/pubmatic/pubmatic.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go index 2dfba673734..be3ebb313f3 100644 --- a/adapters/pubmatic/pubmatic.go +++ b/adapters/pubmatic/pubmatic.go @@ -418,8 +418,7 @@ func validateAdSlot(adslot string, imp *openrtb.Imp) error { //In case of video, size could be derived from the player size if imp.Banner != nil { - imp.Banner.H = openrtb.Uint64Ptr(uint64(height)) - imp.Banner.W = openrtb.Uint64Ptr(uint64(width)) + imp.Banner = assignBannerHeightAndWidth(imp.Banner, uint64(height), uint64(width)) } } else { return errors.New(fmt.Sprintf("Invalid adSlot %v", adSlotStr)) @@ -428,25 +427,25 @@ func validateAdSlot(adslot string, imp *openrtb.Imp) error { return nil } -func assignBannerSize(banner *openrtb.Banner) error { - if banner == nil { - return nil - } - +func assignBannerSize(banner *openrtb.Banner) (*openrtb.Banner, error) { if banner.W != nil && banner.H != nil { - return nil + return banner, nil } if len(banner.Format) == 0 { - return errors.New(fmt.Sprintf("No sizes provided for Banner %v", banner.Format)) + return nil, errors.New(fmt.Sprintf("No sizes provided for Banner %v", banner.Format)) } - banner.W = new(uint64) - *banner.W = banner.Format[0].W - banner.H = new(uint64) - *banner.H = banner.Format[0].H + return assignBannerHeightAndWidth(banner, banner.Format[0].H, banner.Format[0].H), nil +} - return nil +func assignBannerHeightAndWidth(banner *openrtb.Banner, h uint64, w uint64) *openrtb.Banner { + bannerCopy := *banner + + bannerCopy.W = openrtb.Uint64Ptr(w) + bannerCopy.H = openrtb.Uint64Ptr(h) + + return &bannerCopy } // parseImpressionObject parse the imp to get it ready to send to pubmatic @@ -489,9 +488,11 @@ func parseImpressionObject(imp *openrtb.Imp, wrapExt *string, pubID *string) err } if imp.Banner != nil { - if err := assignBannerSize(imp.Banner); err != nil { + bannerCopy, err := assignBannerSize(imp.Banner) + if err != nil { return err } + imp.Banner = bannerCopy } if pubmaticExt.Keywords != nil && len(pubmaticExt.Keywords) != 0 {