Skip to content

Commit

Permalink
Merge branch 'arch_24565/relayd_fail_on_reports_containing_non_utf_8_…
Browse files Browse the repository at this point in the history
…characters_pr' into branches/rudder/8.0
  • Loading branch information
Jenkins CI committed Mar 25, 2024
2 parents 40a0c75 + 59466b2 commit d058f25
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions relay/sources/relayd/src/data/runlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::{
collections::HashSet,
convert::TryFrom,
fmt::{self, Display},
fs::read_to_string,
fs::File,
io::Read,
path::Path,
str::FromStr,
};
Expand Down Expand Up @@ -108,7 +109,12 @@ impl RunLog {
RudderError::InvalidRunInfo(path.as_ref().to_str().unwrap_or("").to_string())
})?,
)?;
RunLog::try_from((info, read_to_string(path)?.as_ref()))
let mut runlog_file = File::open(path)?;
let mut buffer = Vec::new();
let _ = runlog_file.read_to_end(&mut buffer)?;
// Don't fail on non UTF-8 input
let runlog_str = String::from_utf8_lossy(&buffer);
RunLog::try_from((info, runlog_str.as_ref()))
}

pub fn without_types(&self, types: &HashSet<String>) -> Self {
Expand Down Expand Up @@ -215,7 +221,7 @@ impl TryFrom<(RunInfo, Vec<RawReport>)> for RunLog {

#[cfg(test)]
mod tests {
use std::fs::read_dir;
use std::fs::{read_dir, read_to_string};

use chrono::DateTime;

Expand Down
3 changes: 2 additions & 1 deletion relay/sources/relayd/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ pub fn signature(input: &[u8], certs: &Stack<X509>) -> Result<String, Error> {

// We have validated the presence of a plain text MIME type, let's parse
// content as a string.
Ok(String::from_utf8(message)?)
// Don't fail on non UTF-8 input
Ok(String::from_utf8_lossy(&message).into_owned())
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@
"component": "end",
"key_value": "20200407-053748-e976e8d5",
"event_type": "control",
"msg": "End execution",
"msg": "End �xecution with non-utf8",
"policy": "Common",
"node_id": "e745a140-40bc-4b86-b6dc-084488fc906b",
"execution_datetime": "2020-04-07T11:20:58+00:00",
"report_id": "0"
}
]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
2020-04-07T11:20:58+00:00 R: @@execution scheduler@@result_success@@dsc-agent-all@@dsc-common-all@@0@@Agent Configuration@@Agent-Schedule@@2020-04-07 13:20:57+02:00##e745a140-40bc-4b86-b6dc-084488fc906b@#File C:\Program Files\Rudder\share\scheduler\Rudder-Agent.xml content already match template C:\Program Files\Rudder\policy\dsc-common\1.0\template\Rudder-Agent.xml
2020-04-07T11:20:58+00:00 R: @@execution scheduler@@result_success@@dsc-agent-all@@dsc-common-all@@0@@Agent tasks@@Rudder-Agent@@2020-04-07 13:20:57+02:00##e745a140-40bc-4b86-b6dc-084488fc906b@#The Rudder-Inventory task, scheduled to be run every night
2020-04-07T11:20:58+00:00 R: @@execution scheduler@@result_success@@dsc-agent-all@@dsc-common-all@@0@@Agent tasks@@Rudder-Inventory@@2020-04-07 13:20:57+02:00##e745a140-40bc-4b86-b6dc-084488fc906b@#The Rudder-Inventory task, scheduled to be run every night
2020-04-07T11:20:58+00:00 R: @@Common@@control@@rudder@@run@@0@@end@@20200407-053748-e976e8d5@@2020-04-07 13:20:57+02:00##e745a140-40bc-4b86-b6dc-084488fc906b@#End execution
2020-04-07T11:20:58+00:00 R: @@Common@@control@@rudder@@run@@0@@end@@20200407-053748-e976e8d5@@2020-04-07 13:20:57+02:00##e745a140-40bc-4b86-b6dc-084488fc906b@#End �xecution with non-utf8

0 comments on commit d058f25

Please sign in to comment.