Skip to content

does not take UTF-8 more byte character length into account when writing data to a file #133

@ghost

Description

I have:

		begin
			# Does not seem to correctly set permissions on open
			# https://stackoverflow.com/questions/7713850/unable-to-create-file-with-correct-permissions-using-netssh-library
			filehandle = @sftp.open!(newauthkeyfile, 'w', :permissions => 0600)
			@sftp.fsetstat!(filehandle, {:permissions => 0600})
			# Does not take a permissions argument this way
			@sftp.file.open(newauthkeyfile , "w" ) do | file |
				authkeys=["Dozentenschlüssel", "1234567890"]
				authkeys.each do | line |
					puts line
					file.puts line
					wantedsize += line.length + 1
				end
			end
			@sftp.loop
		rescue Net::SFTP::StatusException => exception
			puts	exception.message
			puts "ERROR: Can't open authorized_keys for writing! Skipped."
			return
		end

(source from https://github.com/proact-de/distkeys with some minor adaptions made during debugging this)

which should produce:

Dozentenschlüssel
1234567890

But it produces:

root@debiantemplate:~# cat .ssh/authorized_keys
Dozentenschlüsse
1234567890

As hexdump:

root@debiantemplate:~# hd .ssh/authorized_keys
00000000  44 6f 7a 65 6e 74 65 6e  73 63 68 6c c3 bc 73 73  |Dozentenschl..ss|
00000010  65 0a 31 32 33 34 35 36  37 38 39 30 0a           |e.1234567890.|
0000001d

Just using "puts" to terminal produces the correct result. I bet Net:SFTP overloads the method and it has to do with the SFTP specific implementation.

If you use "Dozentenschlüüssel" instead then two bytes are missing.

I did not check whether the setting permissions issue I worked around in my code is still there or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions