Skip to content

Commit ed72914

Browse files
committed
LP: Security: sanitize params when executing converter
1 parent 6f32625 commit ed72914

4 files changed

+28
-9
lines changed

main/lp/openoffice_document.class.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public function convert_document($file, $action_after_conversion = 'make_lp', $s
7070
if (!empty($size)) {
7171
list($w, $h) = explode('x', $size);
7272
if (!empty($w) && !empty($h)) {
73-
$this->slide_width = $w;
74-
$this->slide_height = $h;
73+
$this->slide_width = (int) $w;
74+
$this->slide_height = (int) $h;
7575
}
7676
}
7777

@@ -106,6 +106,7 @@ public function convert_document($file, $action_after_conversion = 'make_lp', $s
106106

107107
$files = [];
108108
$return = 0;
109+
$cmd = escapeshellcmd($cmd);
109110
$shell = exec($cmd, $files, $return);
110111

111112
if ($return != 0) { // If the java application returns an error code.
@@ -211,7 +212,9 @@ public function convertCopyDocument($originalPath, $convertedPath, $convertedTit
211212

212213
$cmd .= ' -p '.api_get_setting('service_ppt2lp', 'port');
213214
// Call to the function implemented by child.
214-
$cmd .= ' "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.'/'.$this->created_dir.'"';
215+
$cmd .= ' "'.Security::sanitizeExecParam($this->base_work_dir.'/'.$this->file_path)
216+
.'" "'
217+
.Security::sanitizeExecParam($this->base_work_dir.'/'.$this->created_dir).'"';
215218
// To allow openoffice to manipulate docs.
216219
@chmod($this->base_work_dir, $permissionFolder);
217220
@chmod($this->base_work_dir.'/'.$this->file_path, $permissionFile);
@@ -221,6 +224,7 @@ public function convertCopyDocument($originalPath, $convertedPath, $convertedTit
221224

222225
$files = [];
223226
$return = 0;
227+
$cmd = escapeshellcmd($cmd);
224228
$shell = exec($cmd, $files, $return);
225229
// TODO: Chown is not working, root keep user privileges, should be www-data
226230
@chown($this->base_work_dir.'/'.$this->created_dir, 'www-data');

main/lp/openoffice_presentation.class.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,23 @@ public function make_lp($files = [])
247247
public function add_command_parameters()
248248
{
249249
if (empty($this->slide_width) || empty($this->slide_height)) {
250-
list($this->slide_width, $this->slide_height) = explode('x', api_get_setting('service_ppt2lp', 'size'));
250+
list($w, $h) = explode('x', api_get_setting('service_ppt2lp', 'size'));
251+
252+
$this->slide_width = (int) $w;
253+
$this->slide_height = (int) $h;
251254
}
252255

253-
return ' -w '.$this->slide_width.' -h '.$this->slide_height.' -d oogie "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.$this->created_dir.'.html"';
256+
return ' -w '.$this->slide_width.' -h '.$this->slide_height.' -d oogie "'
257+
.Security::sanitizeExecParam($this->base_work_dir.'/'.$this->file_path)
258+
.'" "'
259+
.Security::sanitizeExecParam($this->base_work_dir.$this->created_dir.'.html')
260+
.'"';
254261
}
255262

256263
public function set_slide_size($width, $height)
257264
{
258-
$this->slide_width = $width;
259-
$this->slide_height = $height;
265+
$this->slide_width = (int) $width;
266+
$this->slide_height = (int) $height;
260267
}
261268

262269
public function add_docs_to_visio($files = [])

main/lp/openoffice_text.class.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ public function dealPerPage($header, $body)
331331
*/
332332
public function add_command_parameters()
333333
{
334-
return ' -d woogie "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html"';
334+
return ' -d woogie "'
335+
.Security::sanitizeExecParam($this->base_work_dir.'/'.$this->file_path)
336+
.'" "'
337+
.Security::sanitizeExecParam($this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html')
338+
.'"';
335339
}
336340

337341
/**

main/lp/openoffice_text_document.class.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ public function dealPerPage($header, $body)
333333
*/
334334
public function add_command_parameters()
335335
{
336-
return ' -d woogie "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html"';
336+
return ' -d woogie "'
337+
.Security::sanitizeExecParam($this->base_work_dir.'/'.$this->file_path)
338+
.'" "'
339+
.Security::sanitizeExecParam($this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html')
340+
.'"';
337341
}
338342

339343
/**

0 commit comments

Comments
 (0)