summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-11-23 01:35:12 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-11-23 01:35:12 +0000
commit41618486876ed6c8c1c9d4fbe264214fdbefd944 (patch)
treef9bbf7d8891c7219d4df3f4f8ad9280a974a40b5
parent28898338bd04585d9fc995b23af2399660a700ae (diff)
Don't access buf[strlen(buf) - 1] for zero-length strings.
``ok by me'' djm@.
-rw-r--r--usr.bin/ssh/misc.c4
-rw-r--r--usr.bin/ssh/sftp.c6
2 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c
index 6bdaea1ada0..26fbac288cc 100644
--- a/usr.bin/ssh/misc.c
+++ b/usr.bin/ssh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.64 2006/08/03 03:34:42 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.65 2006/11/23 01:35:11 ray Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -603,6 +603,8 @@ read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz,
u_long *lineno)
{
while (fgets(buf, bufsz, f) != NULL) {
+ if (buf[0] == '\0')
+ continue;
(*lineno)++;
if (buf[strlen(buf) - 1] == '\n' || feof(f)) {
return 0;
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c
index 804ed487ae6..fc806fe16cc 100644
--- a/usr.bin/ssh/sftp.c
+++ b/usr.bin/ssh/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.93 2006/09/30 17:48:22 ray Exp $ */
+/* $OpenBSD: sftp.c,v 1.94 2006/11/23 01:35:11 ray Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -286,11 +286,11 @@ static char *
path_append(char *p1, char *p2)
{
char *ret;
- int len = strlen(p1) + strlen(p2) + 2;
+ size_t len = strlen(p1) + strlen(p2) + 2;
ret = xmalloc(len);
strlcpy(ret, p1, len);
- if (p1[strlen(p1) - 1] != '/')
+ if (p1[0] != '\0' && p1[strlen(p1) - 1] != '/')
strlcat(ret, "/", len);
strlcat(ret, p2, len);