Jira (FACT-3206) Facter::Core::Execution.exec strips leading and trailing NULL bytes

11 views
Skip to first unread message

Kai Burghardt (Jira)

unread,
Jun 3, 2023, 2:24:02 PM6/3/23
to puppe...@googlegroups.com
Kai Burghardt created an issue
 
Facter / Bug FACT-3206
Facter::Core::Execution.exec strips leading and trailing NULL bytes
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2023/06/03 11:23 AM
Priority: Normal Normal
Reporter: Kai Burghardt
  1. (on the puppet master) create a custom fact

    Facter.add('test') do
    	setcode do
    		# This makes
    		# 	Error: Facter: Error while resolving custom fact fact='sysctl', resolution='<anonymous>': invalid byte sequence in UTF-8
    		# go away:
    		Encoding.default_external = Encoding::ASCII_8BIT
    		
    		value = Facter::Core::Execution.execute('/bin/cat /tmp/null')
    		
    		value.bytesize
    	end
    end 

  1. (on the node) create some content containing leading and/or trailing NULL bytes

    echo -en "\x00\x00\x00\x00" > /tmp/null
    

  1. (on the node) synchronize so the test fact becomes available
  2. (on the node) query the new fact

puppet facts test

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.21#820021-sha1:38274c8)
Atlassian logo

Kai Burghardt (Jira)

unread,
Jun 3, 2023, 2:27:01 PM6/3/23
to puppe...@googlegroups.com
Kai Burghardt updated an issue
Change By: Kai Burghardt
Acceptance Criteria: {{puppet facts test}} reports {{4}} ({_}four{_} bytes)
Remaining Estimate: 1 hour
Original Estimate: 1 hour
# (on the puppet master) create a custom fact
{code: java ruby }
Facter.add('test') do
setcode do
  # This makes
  #  Error: Facter: Error while resolving custom fact fact='sysctl', resolution='<anonymous>': invalid byte sequence in UTF-8
  # go away:
  Encoding.default_external = Encoding::ASCII_8BIT
  
  value = Facter::Core::Execution.execute('/bin/cat /tmp/null')
  
  value.bytesize
end
end {code}

# (on the node) create some content containing leading and/or trailing NULL bytes
{code: java shell }
echo -en "\x00\x00\x00\x00" > /tmp/null
{code}

# (on the node) synchronize so the {{test}} fact becomes available
# (on the node) query the new fact


{code: java shell }
puppet facts test{code} This reports {{0}} (zero)

Kai Burghardt (Jira)

unread,
Jun 3, 2023, 2:30:01 PM6/3/23
to puppe...@googlegroups.com
Kai Burghardt updated an issue
# (on the puppet master) create a custom fact{code:ruby}Facter.add('test') do

setcode do
  # This makes
  #  Error: Facter: Error while resolving custom fact fact=' sysctl test ', resolution='<anonymous>': invalid byte sequence in UTF-8

  # go away:
  Encoding.default_external = Encoding::ASCII_8BIT
  
  value = Facter::Core::Execution.execute('/bin/cat /tmp/null')
  
  value.bytesize
end
end{code}
# (on the node) create some content containing leading and/or trailing NULL bytes{code:shell}echo -en "\x00\x00\x00\x00" > /tmp/null{code}

# (on the node) synchronize so the {{test}} fact becomes available
# (on the node) query the new fact{code:shell}puppet facts test{code}This reports {{0}} (zero)

Kai Burghardt (Jira)

unread,
Jun 3, 2023, 2:32:02 PM6/3/23
to puppe...@googlegroups.com
Kai Burghardt updated an issue
Change By: Kai Burghardt
Acceptance Criteria: {{puppet facts test --value-only }} reports {{4}} ({_}four{_} bytes)
# (on the puppet master) create a custom fact{code:ruby}Facter.add('test') do
setcode do
  # This makes
  #  Error: Facter: Error while resolving custom fact fact='test', resolution='<anonymous>': invalid byte sequence in UTF-8

  # go away:
  Encoding.default_external = Encoding::ASCII_8BIT
  
  value = Facter::Core::Execution.execute('/bin/cat /tmp/null')
  
  value.bytesize
end
end{code}
# (on the node) create some content containing leading and/or trailing NULL bytes{code:shell}echo -en "\x00\x00\x00\x00" > /tmp/null{code}
# (on the node) synchronize so the {{test}} fact becomes available
# (on the node) query the new fact{code:shell}puppet facts test --value-only {code}This reports {{0}} (zero) .

Kai Burghardt (Jira)

unread,
Jun 3, 2023, 2:39:01 PM6/3/23
to puppe...@googlegroups.com
Kai Burghardt updated an issue
Change By: Kai Burghardt
Method Found: Needs Assessment Manual Test
Affects Version/s: FACT 4.2.14

Kai Burghardt (Jira)

unread,
Jun 6, 2023, 4:47:01 PM6/6/23
to puppe...@googlegroups.com
Kai Burghardt commented on Bug FACT-3206
 
Re: Facter::Core::Execution.exec strips leading and trailing NULL bytes

sad.png I see. Thank you for linking the other issue.

This is grabbing data (a set of numbers) via a binary interface. The information is also available in human-readable form.

  • It is just less of a hassle to take and process four 8-byte sequences (if they were available via Facter::Core::Execution.exec),
  • instead of processing the human-readable output and separating textual labels/suffixes etc. from the actual numbers,
  • and let’s not forget the round-trip conversion (binary number → string → back to a binary number).
Reply all
Reply to author
Forward
0 new messages