bug in ssh-keyscan.c --
Paul Townsend
aab at aab.cc.purdue.edu
Thu Mar 21 14:44:41 EST 2002
=====
Ladies/Gents,
"ssh-keyscan.c" can't be linked statically against "libssh.a". You end
up with `fatal()' being doubly defined.
The patch below deletes the new "ssh-keyscan.c:fatal()" function and
and restores the "ssh-keyscan.c:fatal_callback()" function with modifi-
cations. The problem that both attempt to alleviate is the setting of
the <called> variable in the "log.c:fatal_cleanup()" function. In the
current code, it can be called once only. The second time it's called,
an immediate "exit(255)" is executed. Unfortunately, `ssh-keyscan'
wants to ignore fatal errors encountered while accessing the server's
keys so this is not good thing.
My personal approach converts the internal static variable to a global
variable and allows the user cleanup function (fatal_callback) to clear
it if desired. Other than kludginess, it should not affect the other
executables and it will work with both static and dynamic linking.
-- Paul Townsend (aab at purdue.edu)
p.s., The first part of the patch is fluff so that I can tell which key
is currently being processed. PT
=-=-=-=-=-=
--- ssh-keyscan.c.orig Mon Mar 4 20:54:53 2002
+++ ssh-keyscan.c Wed Mar 20 21:35:08 2002
@@ -538,7 +538,11 @@
confree(s);
return;
}
- fprintf(stderr, "# %s %s\n", c->c_name, chop(buf));
+ n = c->c_keytype;
+ if (n < KT_RSA1 || n > KT_RSA || n == 3)
+ n = 6; /* paranoia ? */
+ cp = "RSA1DSA RSA UNKN";
+ fprintf(stderr, "# %4.4s %s %s\n", cp + (n / 2) * 4, c->c_name, chop(buf));
n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",
c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,
c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);
@@ -665,17 +669,14 @@
}
}
-void
-fatal(const char *fmt,...)
+extern int fatal_cleanup_called;
+static void
+fatal_callback(void *arg)
{
- va_list args;
- va_start(args, fmt);
- do_log(SYSLOG_LEVEL_FATAL, fmt, args);
- va_end(args);
- if (nonfatal_fatal)
+ if (nonfatal_fatal) {
+ fatal_cleanup_called = 0;
longjmp(kexjmp, -1);
- else
- fatal_cleanup();
+ }
}
static void
@@ -777,6 +778,7 @@
usage();
log_init("ssh-keyscan", log_level, SYSLOG_FACILITY_USER, 1);
+ fatal_add_cleanup(fatal_callback, NULL);
maxfd = fdlim_get(1);
if (maxfd < 0)
--- log.c.orig Tue Feb 26 12:52:15 2002
+++ log.c Wed Mar 20 21:13:04 2002
@@ -216,15 +216,16 @@
}
/* Cleanup and exit */
+int fatal_cleanup_called = 0;
void
fatal_cleanup(void)
{
struct fatal_cleanup *cu, *next_cu;
- static int called = 0;
- if (called)
+ if (fatal_cleanup_called)
exit(255);
- called = 1;
+ fatal_cleanup_called = 1;
+
/* Call cleanup functions. */
for (cu = fatal_cleanups; cu; cu = next_cu) {
next_cu = cu->next;
More information about the openssh-unix-dev
mailing list