]> git.mxchange.org Git - friendica.git/commitdiff
Issue 9926: Limit the length of data to store in the apcontact table
authorMichael <heluecht@pirati.ca>
Mon, 24 May 2021 19:44:24 +0000 (19:44 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 24 May 2021 19:44:24 +0000 (19:44 +0000)
src/Database/DBStructure.php
src/Model/APContact.php

index 82e405942f942c9829158c776b5d162ac17d204d..04ba956bc973e2ddea7a8a1537752b71c7658181 100644 (file)
@@ -241,6 +241,10 @@ class DBStructure
                // Assign all field that are present in the table
                foreach ($fieldnames as $field) {
                        if (isset($data[$field])) {
+                               // Limit the length of varchar, varbinary, char and binrary fields
+                               if (is_string($data[$field]) && preg_match("/[char|binary]\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
+                                       $data[$field] = mb_substr($data[$field], 0, $result[1]);
+                               }
                                $fields[$field] = $data[$field];
                        }
                }
index 7a63e413cab3ee5f6f26d6ad8c5b8acfe1c4a629..28bb31c83d94c5f61ff6ea670da27f4270142634 100644 (file)
@@ -26,6 +26,7 @@ use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
 use Friendica\DI;
 use Friendica\Network\Probe;
 use Friendica\Protocol\ActivityNamespace;
@@ -349,6 +350,9 @@ class APContact
                        DBA::delete('apcontact', ['url' => $url]);
                }
 
+               // Limit the length on incoming fields
+               $apcontact = DBStructure::getFieldsForTable('apcontact', $apcontact);
+
                if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
                        DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
                } else {