summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2013-05-16 20:22:46 +1000
committerDarren Tucker <dtucker@zip.com.au>2013-05-16 20:22:46 +1000
commit2ca51bf140ef2c2409fd220778529dc17c11d8fa (patch)
treed5e8369d537f14daa635a3faf2b4eac763e4903d
parent6aa3eacc5e5f39702b6dd5b27970d9fd97bc2383 (diff)
- tedu@cvs.openbsd.org 2013/04/23 17:49:45
[misc.c] use xasprintf instead of a series of strlcats and strdup. ok djm
-rw-r--r--ChangeLog4
-rw-r--r--misc.c21
2 files changed, 14 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 97eccf9b5..4864be92f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
120130516 120130516
2 - (djm) [contrib/ssh-copy-id] Fix bug that could cause "rm *" to be 2 - (djm) [contrib/ssh-copy-id] Fix bug that could cause "rm *" to be
3 executed if mktemp failed; bz#2105 ok dtucker@ 3 executed if mktemp failed; bz#2105 ok dtucker@
4 - (dtucker) OpenBSD CVS Sync
5 - tedu@cvs.openbsd.org 2013/04/23 17:49:45
6 [misc.c]
7 use xasprintf instead of a series of strlcats and strdup. ok djm
4 8
520130510 920130510
6 - (dtucker) [configure.ac] Enable -Wsizeof-pointer-memaccess if the compiler 10 - (dtucker) [configure.ac] Enable -Wsizeof-pointer-memaccess if the compiler
diff --git a/misc.c b/misc.c
index 9e287433a..ee5711d19 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.86 2011/09/05 05:59:08 djm Exp $ */ 1/* $OpenBSD: misc.c,v 1.87 2013/04/23 17:49:45 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -517,8 +517,8 @@ freeargs(arglist *args)
517char * 517char *
518tilde_expand_filename(const char *filename, uid_t uid) 518tilde_expand_filename(const char *filename, uid_t uid)
519{ 519{
520 const char *path; 520 const char *path, *sep;
521 char user[128], ret[MAXPATHLEN]; 521 char user[128], *ret;
522 struct passwd *pw; 522 struct passwd *pw;
523 u_int len, slash; 523 u_int len, slash;
524 524
@@ -538,22 +538,21 @@ tilde_expand_filename(const char *filename, uid_t uid)
538 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */ 538 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */
539 fatal("tilde_expand_filename: No such uid %ld", (long)uid); 539 fatal("tilde_expand_filename: No such uid %ld", (long)uid);
540 540
541 if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret))
542 fatal("tilde_expand_filename: Path too long");
543
544 /* Make sure directory has a trailing '/' */ 541 /* Make sure directory has a trailing '/' */
545 len = strlen(pw->pw_dir); 542 len = strlen(pw->pw_dir);
546 if ((len == 0 || pw->pw_dir[len - 1] != '/') && 543 if ((len == 0 || pw->pw_dir[len - 1] != '/'))
547 strlcat(ret, "/", sizeof(ret)) >= sizeof(ret)) 544 sep = "/";
548 fatal("tilde_expand_filename: Path too long"); 545 else
546 sep = "";
549 547
550 /* Skip leading '/' from specified path */ 548 /* Skip leading '/' from specified path */
551 if (path != NULL) 549 if (path != NULL)
552 filename = path + 1; 550 filename = path + 1;
553 if (strlcat(ret, filename, sizeof(ret)) >= sizeof(ret)) 551
552 if (xasprintf(&ret, "%s%s%s", pw->pw_dir, sep, filename) >= MAXPATHLEN)
554 fatal("tilde_expand_filename: Path too long"); 553 fatal("tilde_expand_filename: Path too long");
555 554
556 return (xstrdup(ret)); 555 return (ret);
557} 556}
558 557
559/* 558/*