Skip to content
Permalink
Browse files
Change convtime() from returning long to returning int. On platforms
where sizeof(int) != sizeof(long), convtime could accept values
>MAX_INT which subsequently truncate when stored in an int during
config parsing.  bz#3250, ok djm@
  • Loading branch information
daztucker committed Jan 11, 2021
1 parent 8510c91 commit ca5450d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
@@ -1,4 +1,4 @@
/* $OpenBSD: misc.c,v 1.157 2020/12/22 00:12:22 djm Exp $ */
/* $OpenBSD: misc.c,v 1.158 2021/01/11 02:12:57 dtucker Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@@ -497,7 +497,7 @@ a2tun(const char *s, int *remote)
*
* Return -1 if time string is invalid.
*/
long
int
convtime(const char *s)
{
long total, secs, multiplier;
@@ -514,7 +514,7 @@ convtime(const char *s)
while (*p) {
secs = strtol(p, &endp, 10);
if (p == endp ||
(errno == ERANGE && (secs == LONG_MIN || secs == LONG_MAX)) ||
(errno == ERANGE && (secs == INT_MIN || secs == INT_MAX)) ||
secs < 0)
return -1;

@@ -545,10 +545,10 @@ convtime(const char *s)
default:
return -1;
}
if (secs >= LONG_MAX / multiplier)
if (secs >= INT_MAX / multiplier)
return -1;
secs *= multiplier;
if (total >= LONG_MAX - secs)
if (total >= INT_MAX - secs)
return -1;
total += secs;
if (total < 0)
@@ -1,4 +1,4 @@
/* $OpenBSD: misc.h,v 1.91 2020/12/22 00:12:22 djm Exp $ */
/* $OpenBSD: misc.h,v 1.92 2021/01/11 02:12:57 dtucker Exp $ */

/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -67,7 +67,7 @@ char *colon(char *);
int parse_user_host_path(const char *, char **, char **, char **);
int parse_user_host_port(const char *, char **, char **, int *);
int parse_uri(const char *, const char *, char **, char **, int *, char **);
long convtime(const char *);
int convtime(const char *);
const char *fmt_timeframe(time_t t);
char *tilde_expand_filename(const char *, uid_t);

@@ -1,4 +1,4 @@
/* $OpenBSD: ssh-add.c,v 1.158 2020/10/18 11:32:02 djm Exp $ */
/* $OpenBSD: ssh-add.c,v 1.159 2021/01/11 02:12:58 dtucker Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -84,7 +84,7 @@ static char *default_files[] = {
static int fingerprint_hash = SSH_FP_HASH_DEFAULT;

/* Default lifetime (0 == forever) */
static long lifetime = 0;
static int lifetime = 0;

/* User has to confirm key use */
static int confirm = 0;
@@ -365,7 +365,7 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag,
filename, comment);
if (lifetime != 0) {
fprintf(stderr,
"Lifetime set to %ld seconds\n", lifetime);
"Lifetime set to %d seconds\n", lifetime);
}
if (confirm != 0) {
fprintf(stderr, "The user must confirm "
@@ -420,7 +420,7 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag,
fprintf(stderr, "Certificate added: %s (%s)\n", certpath,
private->cert->key_id);
if (lifetime != 0) {
fprintf(stderr, "Lifetime set to %ld seconds\n",
fprintf(stderr, "Lifetime set to %d seconds\n",
lifetime);
}
if (confirm != 0) {
@@ -603,7 +603,7 @@ load_resident_keys(int agent_fd, const char *skprovider, int qflag)
sshkey_type(keys[i]), fp);
if (lifetime != 0) {
fprintf(stderr,
"Lifetime set to %ld seconds\n", lifetime);
"Lifetime set to %d seconds\n", lifetime);
}
if (confirm != 0) {
fprintf(stderr, "The user must confirm "
@@ -1,4 +1,4 @@
/* $OpenBSD: ssh-agent.c,v 1.267 2020/11/08 22:37:24 djm Exp $ */
/* $OpenBSD: ssh-agent.c,v 1.268 2021/01/11 02:12:58 dtucker Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -150,7 +150,7 @@ u_char lock_salt[LOCK_SALT_SIZE];
extern char *__progname;

/* Default lifetime in seconds (0 == forever) */
static long lifetime = 0;
static int lifetime = 0;

static int fingerprint_hash = SSH_FP_HASH_DEFAULT;

0 comments on commit ca5450d

Please sign in to comment.