[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Workaround in 0.6.0


Hello,



Thanks for the quick reply.  For details on the "b" mode of fopen, please see:



http://www.cplusplus.com/reference/clibrary/cstdio/fopen/



Specifically,



With the mode specifiers above the file is open as a text file. In order to open a file as a binary file, a "b" character has to be included in the mode string. This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").



For a reference to our reasoning for opening the file as binary:



http://stackoverflow.com/questions/7960460/reading-windows-file-stat-returns-incorrect-value

(see the answer)



If there may be any inconsistencies or oversights with this solution, please let me know.



Thanks,

Jonathan



-----Original Message-----
From: Andreas Schneider [mailto:asn@xxxxxxxxxxxxxx]
Sent: Thursday, August 23, 2012 10:27 AM
To: libssh@xxxxxxxxxx
Subject: Re: Workaround in 0.6.0



On Thursday 23 August 2012 06:59:43 you wrote:

> Hello,



Hi,



> Wanted to point out the following to the LibSSH group.

>

> My colleague and I were able to successfully build LibSSH 0.6.0 with a

> few adjustments to the build project.  However, when we attempted to

> utilize the library, we were receiving errors on attempts to authorize

> with a private key.  After much digging around and debugging, we were

> able to find out that the following conditionals were failing:

>

> ssh_pki_import_privkey_file

>

>     if (size != sb.st_size) {

>

> ssh_pki_import_pubkey_file

>

>     if (size != sb.st_size) {

>

> We found that the difference was only one byte in length.  After some

> research, we realized that the newline in our private key file was

> being counted as 2 bytes (\r\n) in the following function:

>

>     rc = stat(filename, &sb);

>

> However, the following:

>

>     size = fread(key_buf, 1, sb.st_size, file);

>

> Was counting the newline as one byte.  In order to solve this issue,

> we simply opened the file with the "binary" option included:

>

>     file = fopen(filename, "rb");



b is a mode from the windows function?



I don't see it in the linux manpage but adding it doesn't result in an error.

I think we're fine adding it.





                -- andreas



--

Andreas Schneider                   GPG-ID: F33E3FC6

www.cryptomilk.org<http://www.cryptomilk.org>                asn@xxxxxxxxxxxxxx<mailto:asn@xxxxxxxxxxxxxx>






________________________________
This e-mail and any files transmitted with it are ShoreTel property, are confidential, and are intended solely for the use of the individual or entity to whom this e-mail is addressed. If you are not one of the named recipient(s) or otherwise have reason to believe that you have received this message in error, please notify the sender and delete this message immediately from your computer. Any other use, retention, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited

Archive administrator: postmaster@lists.cynapses.org