Module Name:    src
Committed By:   christos
Date:           Sat Feb 26 13:30:19 UTC 2022

Modified Files:
        src/crypto/external/bsd/openssh/dist: misc.c

Log Message:
fix merge botch and reduce diff from upstream.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/crypto/external/bsd/openssh/dist/misc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/openssh/dist/misc.c
diff -u src/crypto/external/bsd/openssh/dist/misc.c:1.29 src/crypto/external/bsd/openssh/dist/misc.c:1.30
--- src/crypto/external/bsd/openssh/dist/misc.c:1.29	Wed Feb 23 14:07:20 2022
+++ src/crypto/external/bsd/openssh/dist/misc.c	Sat Feb 26 08:30:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: misc.c,v 1.29 2022/02/23 19:07:20 christos Exp $	*/
+/*	$NetBSD: misc.c,v 1.30 2022/02/26 13:30:19 christos Exp $	*/
 /* $OpenBSD: misc.c,v 1.174 2022/02/11 00:43:56 dtucker Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
@@ -19,7 +19,7 @@
  */
 
 #include "includes.h"
-__RCSID("$NetBSD: misc.c,v 1.29 2022/02/23 19:07:20 christos Exp $");
+__RCSID("$NetBSD: misc.c,v 1.30 2022/02/26 13:30:19 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
@@ -742,7 +742,7 @@ int
 parse_user_host_path(const char *s, char **userp, char **hostp, char **pathp)
 {
 	char *user = NULL, *host = NULL, *path = NULL;
-	char *tmp, *sdup;
+	char *sdup, *tmp;
 	int ret = -1;
 
 	if (userp != NULL)
@@ -1094,8 +1094,7 @@ tilde_expand(const char *filename, uid_t
 	const char *path = NULL, *user = NULL;
 	struct passwd *pw;
 	size_t len;
-	int ret = -1, r;
-	const char *sep, *homedir;
+	int ret = -1, r, slash;
 
 	*retp = NULL;
 	if (*filename != '~') {
@@ -1129,27 +1128,16 @@ tilde_expand(const char *filename, uid_t
 			error_f("No such user %s", user);
 			goto out;
 		}
-		homedir = pw->pw_dir;
-	} else {
-		if ((pw = getpwuid(uid)) == NULL) {	/* ~/path */
-			error_f("No such uid %ld", (long)uid);
-			goto out;
-		}
-		homedir = pw->pw_dir;
+	} else if ((pw = getpwuid(uid)) == NULL) {
+		error_f("No such uid %ld", (long)uid);
+		goto out;
 	}
 
 	/* Make sure directory has a trailing '/' */
-	len = strlen(homedir);
-	if (len == 0 || homedir[len - 1] != '/')
-		sep = "/";
-	else
-		sep = "";
-
-	/* Skip leading '/' from specified path */
-	if (path != NULL)
-		filename = path + 1;
+	slash = (len = strlen(pw->pw_dir)) == 0 || pw->pw_dir[len - 1] != '/';
 
-	if ((r = xasprintf(&s, "%s%s%s", homedir, sep, filename)) <= 0) {
+	if ((r = xasprintf(&s, "%s%s%s", pw->pw_dir,
+	    slash ? "/" : "", path != NULL ? path : "")) <= 0) {
 		error_f("xasprintf failed");
 		goto out;
 	}

Reply via email to