Bugzilla – Attachment 3656 Details for
Bug 3529
`add_host_to_hostfile` should take into consideration that the known_hosts file isn't terminated with a newline character.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Check for newline at end of known_hosts and add it missing. Close FILE * if write fails.
openssh-knownhosts-nonewline.patch (text/plain), 1.23 KB, created by
Darren Tucker
on 2023-02-05 20:33:20 AEDT
(
hide
)
Description:
Check for newline at end of known_hosts and add it missing. Close FILE * if write fails.
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2023-02-05 20:33:20 AEDT
Size:
1.23 KB
patch
obsolete
>diff --git a/hostfile.c b/hostfile.c >index bd49e3ac..72f8f38e 100644 >--- a/hostfile.c >+++ b/hostfile.c >@@ -523,6 +523,14 @@ add_host_to_hostfile(const char *filename, const char *host, > f = fopen(filename, "a"); > if (!f) > return 0; >+ /* Make sure we have a terminating newline. */ >+ if (fseek(f, -1, SEEK_CUR) == 0 && fgetc(f) != '\n') >+ if (fputc('\n', f) != '\n') { >+ error("Failed to add terminating newline to %s: %s", >+ filename, strerror(errno) ); >+ fclose(f); >+ return 0; >+ } > success = write_host_entry(f, host, NULL, key, store_hash); > fclose(f); > return success; >diff --git a/regress/knownhosts.sh b/regress/knownhosts.sh >index dfc768ac..fc17acb0 100644 >--- a/regress/knownhosts.sh >+++ b/regress/knownhosts.sh >@@ -15,3 +15,10 @@ ${SSH} -ohashknownhosts=yes -o stricthostkeychecking=no $opts somehost true \ > > trace "test hashed known hosts" > ${SSH} $opts somehost true || fail "reconnect with hashed known hosts" >+ >+trace "no newline at end of known_hosts" >+printf "something" >$OBJ/known_hosts >+${SSH} $opts -ostricthostkeychecking=no somehost true \ >+ || fail "hostkey update, missing newline, no strict" >+${SSH} $opts -ostricthostkeychecking=yes somehost true \ >+ || fail "reconnect after adding with missing newline"
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
djm
:
ok+
Actions:
View
|
Diff
Attachments on
bug 3529
:
3655
| 3656 |
3657