summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-02-09 01:23:39 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-02-09 01:23:39 +0000
commitf6b7b09a4e1b60594c34eea1a2ef8408460491bf (patch)
tree36140cc66f21890c903ef3a8fd2a13239ef25836
parentaf13ccacaca76646b3e937ed4a8bf48ae9fb2638 (diff)
- deraadt@cvs.openbsd.org 2001/02/08 14:38:54
[scp.c] memory leak fix, and snprintf throughout
-rw-r--r--ChangeLog4
-rw-r--r--scp.c39
2 files changed, 27 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index c00901fcd..ed40993a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,10 @@
17 [auth2.c] 17 [auth2.c]
18 fix typo 18 fix typo
19 - (djm) Update spec files 19 - (djm) Update spec files
20 - (bal) OpenBSD sync:
21 - deraadt@cvs.openbsd.org 2001/02/08 14:38:54
22 [scp.c]
23 memory leak fix, and snprintf throughout
20 24
2120010208 2520010208
22 - (djm) Don't delete external askpass program in make uninstall target. 26 - (djm) Don't delete external askpass program in make uninstall target.
diff --git a/scp.c b/scp.c
index 26d4c2daa..14d8a8af8 100644
--- a/scp.c
+++ b/scp.c
@@ -75,7 +75,7 @@
75 */ 75 */
76 76
77#include "includes.h" 77#include "includes.h"
78RCSID("$OpenBSD: scp.c,v 1.53 2001/02/04 23:56:22 deraadt Exp $"); 78RCSID("$OpenBSD: scp.c,v 1.55 2001/02/08 14:38:54 deraadt Exp $");
79 79
80#include "xmalloc.h" 80#include "xmalloc.h"
81#include "atomicio.h" 81#include "atomicio.h"
@@ -326,7 +326,8 @@ main(argc, argv)
326 326
327 remin = remout = -1; 327 remin = remout = -1;
328 /* Command to be executed on remote system using "ssh". */ 328 /* Command to be executed on remote system using "ssh". */
329 (void) sprintf(cmd, "scp%s%s%s%s", verbose_mode ? " -v" : "", 329 (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
330 verbose_mode ? " -v" : "",
330 iamrecursive ? " -r" : "", pflag ? " -p" : "", 331 iamrecursive ? " -r" : "", pflag ? " -p" : "",
331 targetshouldbedirectory ? " -d" : ""); 332 targetshouldbedirectory ? " -d" : "");
332 333
@@ -397,16 +398,18 @@ toremote(targ, argc, argv)
397 suser = pwd->pw_name; 398 suser = pwd->pw_name;
398 else if (!okname(suser)) 399 else if (!okname(suser))
399 continue; 400 continue;
400 sprintf(bp, 401 snprintf(bp, len,
401 "%s%s -x -o'FallBackToRsh no' -n -l %s %s %s %s '%s%s%s:%s'", 402 "%s%s -x -o'FallBackToRsh no' -n "
403 "-l %s %s %s %s '%s%s%s:%s'",
402 ssh_program, verbose_mode ? " -v" : "", 404 ssh_program, verbose_mode ? " -v" : "",
403 suser, host, cmd, src, 405 suser, host, cmd, src,
404 tuser ? tuser : "", tuser ? "@" : "", 406 tuser ? tuser : "", tuser ? "@" : "",
405 thost, targ); 407 thost, targ);
406 } else { 408 } else {
407 host = cleanhostname(argv[i]); 409 host = cleanhostname(argv[i]);
408 sprintf(bp, 410 snprintf(bp, len,
409 "exec %s%s -x -o'FallBackToRsh no' -n %s %s %s '%s%s%s:%s'", 411 "exec %s%s -x -o'FallBackToRsh no' -n %s "
412 "%s %s '%s%s%s:%s'",
410 ssh_program, verbose_mode ? " -v" : "", 413 ssh_program, verbose_mode ? " -v" : "",
411 host, cmd, src, 414 host, cmd, src,
412 tuser ? tuser : "", tuser ? "@" : "", 415 tuser ? tuser : "", tuser ? "@" : "",
@@ -420,7 +423,7 @@ toremote(targ, argc, argv)
420 if (remin == -1) { 423 if (remin == -1) {
421 len = strlen(targ) + CMDNEEDS + 20; 424 len = strlen(targ) + CMDNEEDS + 20;
422 bp = xmalloc(len); 425 bp = xmalloc(len);
423 (void) sprintf(bp, "%s -t %s", cmd, targ); 426 (void) snprintf(bp, len, "%s -t %s", cmd, targ);
424 host = cleanhostname(thost); 427 host = cleanhostname(thost);
425 if (do_cmd(host, tuser, bp, &remin, 428 if (do_cmd(host, tuser, bp, &remin,
426 &remout, argc) < 0) 429 &remout, argc) < 0)
@@ -447,7 +450,7 @@ tolocal(argc, argv)
447 len = strlen(_PATH_CP) + strlen(argv[i]) + 450 len = strlen(_PATH_CP) + strlen(argv[i]) +
448 strlen(argv[argc - 1]) + 20; 451 strlen(argv[argc - 1]) + 20;
449 bp = xmalloc(len); 452 bp = xmalloc(len);
450 (void) sprintf(bp, "exec %s%s%s %s %s", _PATH_CP, 453 (void) snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP,
451 iamrecursive ? " -r" : "", pflag ? " -p" : "", 454 iamrecursive ? " -r" : "", pflag ? " -p" : "",
452 argv[i], argv[argc - 1]); 455 argv[i], argv[argc - 1]);
453 if (verbose_mode) 456 if (verbose_mode)
@@ -474,7 +477,7 @@ tolocal(argc, argv)
474 host = cleanhostname(host); 477 host = cleanhostname(host);
475 len = strlen(src) + CMDNEEDS + 20; 478 len = strlen(src) + CMDNEEDS + 20;
476 bp = xmalloc(len); 479 bp = xmalloc(len);
477 (void) sprintf(bp, "%s -f %s", cmd, src); 480 (void) snprintf(bp, len, "%s -f %s", cmd, src);
478 if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) { 481 if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {
479 (void) xfree(bp); 482 (void) xfree(bp);
480 ++errs; 483 ++errs;
@@ -531,7 +534,7 @@ syserr: run_err("%s: %s", name, strerror(errno));
531 * Make it compatible with possible future 534 * Make it compatible with possible future
532 * versions expecting microseconds. 535 * versions expecting microseconds.
533 */ 536 */
534 (void) sprintf(buf, "T%lu 0 %lu 0\n", 537 (void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",
535 (u_long) stb.st_mtime, 538 (u_long) stb.st_mtime,
536 (u_long) stb.st_atime); 539 (u_long) stb.st_atime);
537 (void) atomicio(write, remout, buf, strlen(buf)); 540 (void) atomicio(write, remout, buf, strlen(buf));
@@ -539,7 +542,7 @@ syserr: run_err("%s: %s", name, strerror(errno));
539 goto next; 542 goto next;
540 } 543 }
541#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) 544#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
542 sprintf(buf, "C%04o %lu %s\n", 545 snprintf(buf, sizeof buf, "C%04o %lu %s\n",
543 (u_int) (stb.st_mode & FILEMODEMASK), 546 (u_int) (stb.st_mode & FILEMODEMASK),
544 (u_long) stb.st_size, last); 547 (u_long) stb.st_size, last);
545 if (verbose_mode) { 548 if (verbose_mode) {
@@ -608,7 +611,7 @@ rsource(name, statp)
608 else 611 else
609 last++; 612 last++;
610 if (pflag) { 613 if (pflag) {
611 (void) sprintf(path, "T%lu 0 %lu 0\n", 614 (void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",
612 (u_long) statp->st_mtime, 615 (u_long) statp->st_mtime,
613 (u_long) statp->st_atime); 616 (u_long) statp->st_atime);
614 (void) atomicio(write, remout, path, strlen(path)); 617 (void) atomicio(write, remout, path, strlen(path));
@@ -617,7 +620,7 @@ rsource(name, statp)
617 return; 620 return;
618 } 621 }
619 } 622 }
620 (void) sprintf(path, "D%04o %d %.1024s\n", 623 (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",
621 (u_int) (statp->st_mode & FILEMODEMASK), 0, last); 624 (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
622 if (verbose_mode) 625 if (verbose_mode)
623 fprintf(stderr, "Entering directory: %s", path); 626 fprintf(stderr, "Entering directory: %s", path);
@@ -635,7 +638,7 @@ rsource(name, statp)
635 run_err("%s/%s: name too long", name, dp->d_name); 638 run_err("%s/%s: name too long", name, dp->d_name);
636 continue; 639 continue;
637 } 640 }
638 (void) sprintf(path, "%s/%s", name, dp->d_name); 641 (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name);
639 vect[0] = path; 642 vect[0] = path;
640 source(1, vect); 643 source(1, vect);
641 } 644 }
@@ -765,9 +768,13 @@ sink(argc, argv)
765 size_t need; 768 size_t need;
766 769
767 need = strlen(targ) + strlen(cp) + 250; 770 need = strlen(targ) + strlen(cp) + 250;
768 if (need > cursize) 771 if (need > cursize) {
772 if (namebuf)
773 xfree(namebuf);
769 namebuf = xmalloc(need); 774 namebuf = xmalloc(need);
770 (void) sprintf(namebuf, "%s%s%s", targ, 775 cursize = need;
776 }
777 (void) snprintf(namebuf, need, "%s%s%s", targ,
771 *targ ? "/" : "", cp); 778 *targ ? "/" : "", cp);
772 np = namebuf; 779 np = namebuf;
773 } else 780 } else