From 2808d18ca47ad3d251836c555f0e22aaca03d15c Mon Sep 17 00:00:00 2001 From: "markus@openbsd.org" Date: Mon, 9 Jul 2018 21:26:02 +0000 Subject: upstream: sshd: switch loginmsg to sshbuf API; ok djm@ OpenBSD-Commit-ID: f3cb4e54bff15c593602d95cc43e32ee1a4bac42 --- sshlogin.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'sshlogin.c') diff --git a/sshlogin.c b/sshlogin.c index cea3e7697..1b2ee5f85 100644 --- a/sshlogin.c +++ b/sshlogin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshlogin.c,v 1.32 2015/12/26 20:51:35 guenther Exp $ */ +/* $OpenBSD: sshlogin.c,v 1.33 2018/07/09 21:26:02 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -55,13 +55,15 @@ #include #include +#include "sshlogin.h" +#include "ssherr.h" #include "loginrec.h" #include "log.h" -#include "buffer.h" +#include "sshbuf.h" #include "misc.h" #include "servconf.h" -extern Buffer loginmsg; +extern struct sshbuf *loginmsg; extern ServerOptions options; /* @@ -88,8 +90,9 @@ static void store_lastlog_message(const char *user, uid_t uid) { #ifndef NO_SSH_LASTLOG - char *time_string, hostname[HOST_NAME_MAX+1] = "", buf[512]; + char *time_string, hostname[HOST_NAME_MAX+1] = ""; time_t last_login_time; + int r; if (!options.print_lastlog) return; @@ -97,7 +100,9 @@ store_lastlog_message(const char *user, uid_t uid) # ifdef CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG time_string = sys_auth_get_lastlogin_msg(user, uid); if (time_string != NULL) { - buffer_append(&loginmsg, time_string, strlen(time_string)); + if ((r = sshbuf_put(loginmsg, + time_string, strlen(time_string))) != 0) + fatal("%s: buffer error: %s", __func__, ssh_err(r)); free(time_string); } # else @@ -108,12 +113,13 @@ store_lastlog_message(const char *user, uid_t uid) time_string = ctime(&last_login_time); time_string[strcspn(time_string, "\n")] = '\0'; if (strcmp(hostname, "") == 0) - snprintf(buf, sizeof(buf), "Last login: %s\r\n", + r = sshbuf_putf(loginmsg, "Last login: %s\r\n", time_string); else - snprintf(buf, sizeof(buf), "Last login: %s from %s\r\n", + r = sshbuf_putf(loginmsg, "Last login: %s from %s\r\n", time_string, hostname); - buffer_append(&loginmsg, buf, strlen(buf)); + if (r != 0) + fatal("%s: buffer error: %s", __func__, ssh_err(r)); } # endif /* CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG */ #endif /* NO_SSH_LASTLOG */ -- cgit v1.2.3