Skip to content

Commit cafc0e0

Browse files
authored
Update processes cmd column to longtext (#26430)
fix #25948
1 parent e83188c commit cafc0e0

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2026 Teclib' and contributors.
11+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
12+
*
13+
* ---------------------------------------------------------------------
14+
*
15+
* LICENSE
16+
*
17+
* This file is part of GLPI.
18+
*
19+
* This program is free software: you can redistribute it and/or modify
20+
* it under the terms of the GNU General Public License as published by
21+
* the Free Software Foundation, either version 3 of the License, or
22+
* (at your option) any later version.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
31+
*
32+
* ---------------------------------------------------------------------
33+
*/
34+
35+
/**
36+
* @var Migration $migration
37+
*/
38+
// see #25948
39+
$migration->changeField('glpi_items_processes', 'cmd', 'cmd', 'longtext');

‎install/mysql/glpi-empty.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,7 @@ CREATE TABLE `glpi_items_processes` (
38853885
`id` int unsigned NOT NULL AUTO_INCREMENT,
38863886
`itemtype` varchar(100) DEFAULT NULL,
38873887
`items_id` int unsigned NOT NULL DEFAULT '0',
3888-
`cmd` text,
3888+
`cmd` longtext,
38893889
`cpuusage` float NOT NULL DEFAULT '0',
38903890
`memusage` float NOT NULL DEFAULT '0',
38913891
`pid` int NOT NULL DEFAULT '1',

‎tests/functional/Glpi/Inventory/Assets/ProcessTest.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,43 @@ public function testHandleWithoutHistory(): void
223223
$this->assertSame($nb_logs, countElementsInTable(\Log::getTable(), $logs_criteria));
224224
}
225225

226+
public function testHandleLongCommandLine(): void
227+
{
228+
$this->login();
229+
$conf = new Conf();
230+
$this->assertTrue($conf->saveConf([
231+
'import_process' => 1,
232+
]));
233+
$this->logout();
234+
235+
$computer = getItemByTypeName(Computer::class, '_test_pc01');
236+
237+
$converter = new Converter();
238+
$json = json_decode($converter->convert($this->assetProvider()[0]['xml']));
239+
240+
// command line exceeding the 65535 bytes of a TEXT column, see #25948
241+
$cmd = '/usr/bin/java -cp ' . str_repeat('/opt/app/lib/dependency.jar:', 3000);
242+
$this->assertGreaterThan(65535, strlen($cmd));
243+
$json->content->processes[0]->cmd = $cmd;
244+
245+
// inventory is played twice: existing process must be matched and updated
246+
for ($i = 0; $i < 2; $i++) {
247+
$asset = new Process($computer, $json->content->processes);
248+
$asset->setExtraData((array) $json->content);
249+
$this->assertTrue($asset->checkConf($conf));
250+
$asset->prepare();
251+
$asset->handleLinks();
252+
$asset->handle();
253+
}
254+
255+
$processes = getAllDataFromTable(
256+
\Item_Process::getTable(),
257+
['items_id' => $computer->fields['id'], 'itemtype' => Computer::class]
258+
);
259+
$this->assertCount(1, $processes);
260+
$this->assertSame($cmd, current($processes)['cmd']);
261+
}
262+
226263
public function testGenericAssetProcess(): void
227264
{
228265
global $DB;

0 commit comments

Comments
 (0)