Changeset 789 for trunk


Ignore:
Timestamp:
Mar 25, 2023 6:30:53 AM (14 months ago)
Author:
anonymous
Message:

Fix potential bug when writing binary data with filePutContents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r788 r789  
    122122* @author   Quinn Comendant <quinn@strangecode.com>
    123123*/
    124 function getDump($var, $serialize=false, $dump_method=SC_DUMP_PRINT_R)
     124function getDump($var, $serialize=false, $dump_method=SC_DUMP_JSON)
    125125{
    126126    $app =& App::getInstance();
     
    128128    switch ($dump_method) {
    129129    case SC_DUMP_PRINT_R:
    130     default:
    131130        // Print human-readable descriptions of invisible types.
    132131        if (null === $var) {
     
    163162
    164163    case SC_DUMP_JSON:
     164    default:
    165165        $json_flags = $serialize ? 0 : JSON_PRETTY_PRINT;
    166166        return json_encode($var, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | $json_flags);
     
    890890    $app =& App::getInstance();
    891891
     892    if (is_null($content) || is_bool($content) || is_object($content) || is_array($content)) {
     893        $app->logMsg(sprintf("Failed writing to file '%s'. Content is not a string.", $filename), LOG_WARNING, __FILE__, __LINE__);
     894        return false;
     895    }
     896
    892897    // Open file for writing and truncate to zero length.
    893898    if ($fp = fopen($filename, 'w')) {
    894899        if (flock($fp, LOCK_EX)) {
    895             if (!fwrite($fp, $content, mb_strlen($content))) {
     900            if (!fwrite($fp, (string)$content)) {
    896901                $app->logMsg(sprintf('Failed writing to file: %s', $filename), LOG_ERR, __FILE__, __LINE__);
    897902                fclose($fp);
Note: See TracChangeset for help on using the changeset viewer.