common gradient: Fix possible crash in color setter
authorMichal Szczecinski <mihashco89@gmail.com>
Fri, 4 Jun 2021 11:24:29 +0000 (13:24 +0200)
committerHermet Park <chuneon.park@samsung.com>
Mon, 7 Jun 2021 03:26:07 +0000 (12:26 +0900)
Memcpy is not allowed on nullptr. If colorStops is invalid colors are
cleared.

Change-Id: I3f6655a008a0ee7a0ce8abcb20c7692630b45282

src/lib/tvgFill.cpp

index f986523bffb0f3350ca0e897be1d155646d937ae..b3fbc7369895b5f459d89973012a90f13d6e4d09 100644 (file)
@@ -43,11 +43,13 @@ Fill::~Fill()
 
 Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept
 {
+    if ((!colorStops && cnt > 0) || (colorStops && cnt == 0)) return Result::InvalidArguments;
+
     if (cnt == 0) {
         if (pImpl->colorStops) {
             free(pImpl->colorStops);
             pImpl->colorStops = nullptr;
-            pImpl->cnt = cnt;
+            pImpl->cnt = 0;
         }
         return Result::Success;
     }