Bugzilla – Attachment 3657 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]
Open for reading and appending.
file_3529.txt (text/plain), 1.57 KB, created by
Mike
on 2023-02-06 21:43:42 AEDT
(
hide
)
Description:
Open for reading and appending.
Filename:
MIME Type:
Creator:
Mike
Created:
2023-02-06 21:43:42 AEDT
Size:
1.57 KB
patch
obsolete
>diff --git a/hostfile.c b/hostfile.c >index bd49e3ac..cf631ff7 100644 >--- a/hostfile.c >+++ b/hostfile.c >@@ -520,9 +520,17 @@ add_host_to_hostfile(const char *filename, const char *host, > if (key == NULL) > return 1; /* XXX ? */ > hostfile_create_user_ssh_dir(filename, 0); >- f = fopen(filename, "a"); >+ f = fopen(filename, "a+"); > if (!f) > return 0; >+ /* Make sure we have a terminating newline. */ >+ if (fseek(f, -1, SEEK_END) == 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:
git+openssh
:
ok?
(
dtucker
)
Actions:
View
|
Diff
Attachments on
bug 3529
:
3655
|
3656
| 3657