summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2013-06-02 07:31:17 +1000
committerDarren Tucker <dtucker@zip.com.au>2013-06-02 07:31:17 +1000
commita627d42e51ffa71e014d7b2d2c07118122fd3ec3 (patch)
tree7bda769de81f509e28d800916fa20abd37906d79 /sftp.c
parentc7aad0058c957afeb26a3f703e8cb0eddeb62365 (diff)
- djm@cvs.openbsd.org 2013/05/17 00:13:13
[xmalloc.h cipher.c sftp-glob.c ssh-keyscan.c ssh.c sftp-common.c ssh-ecdsa.c auth2-chall.c compat.c readconf.c kexgexs.c monitor.c gss-genr.c cipher-3des1.c kex.c monitor_wrap.c ssh-pkcs11-client.c auth-options.c rsa.c auth2-pubkey.c sftp.c hostfile.c auth2.c servconf.c auth.c authfile.c xmalloc.c uuencode.c sftp-client.c auth2-gss.c sftp-server.c bufaux.c mac.c session.c jpake.c kexgexc.c sshconnect.c auth-chall.c auth2-passwd.c sshconnect1.c buffer.c kexecdhs.c kexdhs.c ssh-rsa.c auth1.c ssh-pkcs11.c auth2-kbdint.c kexdhc.c sshd.c umac.c ssh-dss.c auth2-jpake.c bufbn.c clientloop.c monitor_mm.c scp.c roaming_client.c serverloop.c key.c auth-rsa.c ssh-pkcs11-helper.c ssh-keysign.c ssh-keygen.c match.c channels.c sshconnect2.c addrmatch.c mux.c canohost.c kexecdhc.c schnorr.c ssh-add.c misc.c auth2-hostbased.c ssh-agent.c bufec.c groupaccess.c dns.c packet.c readpass.c authfd.c moduli.c] bye, bye xfree(); ok markus@
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c92
1 files changed, 44 insertions, 48 deletions
diff --git a/sftp.c b/sftp.c
index 12c4958d9..a723fa643 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.144 2013/05/16 09:08:41 dtucker Exp $ */ 1/* $OpenBSD: sftp.c,v 1.145 2013/05/17 00:13:14 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -309,7 +309,7 @@ local_do_ls(const char *args)
309 /* XXX: quoting - rip quoting code from ftp? */ 309 /* XXX: quoting - rip quoting code from ftp? */
310 snprintf(buf, len, _PATH_LS " %s", args); 310 snprintf(buf, len, _PATH_LS " %s", args);
311 local_do_shell(buf); 311 local_do_shell(buf);
312 xfree(buf); 312 free(buf);
313 } 313 }
314} 314}
315 315
@@ -340,7 +340,7 @@ make_absolute(char *p, char *pwd)
340 /* Derelativise */ 340 /* Derelativise */
341 if (p && p[0] != '/') { 341 if (p && p[0] != '/') {
342 abs_str = path_append(pwd, p); 342 abs_str = path_append(pwd, p);
343 xfree(p); 343 free(p);
344 return(abs_str); 344 return(abs_str);
345 } else 345 } else
346 return(p); 346 return(p);
@@ -550,7 +550,7 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd,
550 tmp = xstrdup(g.gl_pathv[i]); 550 tmp = xstrdup(g.gl_pathv[i]);
551 if ((filename = basename(tmp)) == NULL) { 551 if ((filename = basename(tmp)) == NULL) {
552 error("basename %s: %s", tmp, strerror(errno)); 552 error("basename %s: %s", tmp, strerror(errno));
553 xfree(tmp); 553 free(tmp);
554 err = -1; 554 err = -1;
555 goto out; 555 goto out;
556 } 556 }
@@ -566,7 +566,7 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd,
566 } else { 566 } else {
567 abs_dst = xstrdup(filename); 567 abs_dst = xstrdup(filename);
568 } 568 }
569 xfree(tmp); 569 free(tmp);
570 570
571 if (!quiet) 571 if (!quiet)
572 printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst); 572 printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst);
@@ -579,12 +579,12 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd,
579 pflag || global_pflag) == -1) 579 pflag || global_pflag) == -1)
580 err = -1; 580 err = -1;
581 } 581 }
582 xfree(abs_dst); 582 free(abs_dst);
583 abs_dst = NULL; 583 abs_dst = NULL;
584 } 584 }
585 585
586out: 586out:
587 xfree(abs_src); 587 free(abs_src);
588 globfree(&g); 588 globfree(&g);
589 return(err); 589 return(err);
590} 590}
@@ -636,7 +636,7 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd,
636 tmp = xstrdup(g.gl_pathv[i]); 636 tmp = xstrdup(g.gl_pathv[i]);
637 if ((filename = basename(tmp)) == NULL) { 637 if ((filename = basename(tmp)) == NULL) {
638 error("basename %s: %s", tmp, strerror(errno)); 638 error("basename %s: %s", tmp, strerror(errno));
639 xfree(tmp); 639 free(tmp);
640 err = -1; 640 err = -1;
641 goto out; 641 goto out;
642 } 642 }
@@ -652,7 +652,7 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd,
652 } else { 652 } else {
653 abs_dst = make_absolute(xstrdup(filename), pwd); 653 abs_dst = make_absolute(xstrdup(filename), pwd);
654 } 654 }
655 xfree(tmp); 655 free(tmp);
656 656
657 if (!quiet) 657 if (!quiet)
658 printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst); 658 printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst);
@@ -668,10 +668,8 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd,
668 } 668 }
669 669
670out: 670out:
671 if (abs_dst) 671 free(abs_dst);
672 xfree(abs_dst); 672 free(tmp_dst);
673 if (tmp_dst)
674 xfree(tmp_dst);
675 globfree(&g); 673 globfree(&g);
676 return(err); 674 return(err);
677} 675}
@@ -719,7 +717,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
719 /* Add any subpath that also needs to be counted */ 717 /* Add any subpath that also needs to be counted */
720 tmp = path_strip(path, strip_path); 718 tmp = path_strip(path, strip_path);
721 m += strlen(tmp); 719 m += strlen(tmp);
722 xfree(tmp); 720 free(tmp);
723 721
724 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1) 722 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
725 width = ws.ws_col; 723 width = ws.ws_col;
@@ -745,7 +743,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
745 743
746 tmp = path_append(path, d[n]->filename); 744 tmp = path_append(path, d[n]->filename);
747 fname = path_strip(tmp, strip_path); 745 fname = path_strip(tmp, strip_path);
748 xfree(tmp); 746 free(tmp);
749 747
750 if (lflag & LS_LONG_VIEW) { 748 if (lflag & LS_LONG_VIEW) {
751 if (lflag & (LS_NUMERIC_VIEW|LS_SI_UNITS)) { 749 if (lflag & (LS_NUMERIC_VIEW|LS_SI_UNITS)) {
@@ -757,7 +755,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
757 lname = ls_file(fname, &sb, 1, 755 lname = ls_file(fname, &sb, 1,
758 (lflag & LS_SI_UNITS)); 756 (lflag & LS_SI_UNITS));
759 printf("%s\n", lname); 757 printf("%s\n", lname);
760 xfree(lname); 758 free(lname);
761 } else 759 } else
762 printf("%s\n", d[n]->longname); 760 printf("%s\n", d[n]->longname);
763 } else { 761 } else {
@@ -769,7 +767,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
769 c++; 767 c++;
770 } 768 }
771 769
772 xfree(fname); 770 free(fname);
773 } 771 }
774 772
775 if (!(lflag & LS_LONG_VIEW) && (c != 1)) 773 if (!(lflag & LS_LONG_VIEW) && (c != 1))
@@ -839,7 +837,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
839 lname = ls_file(fname, g.gl_statv[i], 1, 837 lname = ls_file(fname, g.gl_statv[i], 1,
840 (lflag & LS_SI_UNITS)); 838 (lflag & LS_SI_UNITS));
841 printf("%s\n", lname); 839 printf("%s\n", lname);
842 xfree(lname); 840 free(lname);
843 } else { 841 } else {
844 printf("%-*s", colspace, fname); 842 printf("%-*s", colspace, fname);
845 if (c >= columns) { 843 if (c >= columns) {
@@ -848,7 +846,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
848 } else 846 } else
849 c++; 847 c++;
850 } 848 }
851 xfree(fname); 849 free(fname);
852 } 850 }
853 851
854 if (!(lflag & LS_LONG_VIEW) && (c != 1)) 852 if (!(lflag & LS_LONG_VIEW) && (c != 1))
@@ -1365,24 +1363,24 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
1365 break; 1363 break;
1366 } 1364 }
1367 if ((aa = do_stat(conn, tmp, 0)) == NULL) { 1365 if ((aa = do_stat(conn, tmp, 0)) == NULL) {
1368 xfree(tmp); 1366 free(tmp);
1369 err = 1; 1367 err = 1;
1370 break; 1368 break;
1371 } 1369 }
1372 if (!(aa->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) { 1370 if (!(aa->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) {
1373 error("Can't change directory: Can't check target"); 1371 error("Can't change directory: Can't check target");
1374 xfree(tmp); 1372 free(tmp);
1375 err = 1; 1373 err = 1;
1376 break; 1374 break;
1377 } 1375 }
1378 if (!S_ISDIR(aa->perm)) { 1376 if (!S_ISDIR(aa->perm)) {
1379 error("Can't change directory: \"%s\" is not " 1377 error("Can't change directory: \"%s\" is not "
1380 "a directory", tmp); 1378 "a directory", tmp);
1381 xfree(tmp); 1379 free(tmp);
1382 err = 1; 1380 err = 1;
1383 break; 1381 break;
1384 } 1382 }
1385 xfree(*pwd); 1383 free(*pwd);
1386 *pwd = tmp; 1384 *pwd = tmp;
1387 break; 1385 break;
1388 case I_LS: 1386 case I_LS:
@@ -1515,10 +1513,8 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
1515 1513
1516 if (g.gl_pathc) 1514 if (g.gl_pathc)
1517 globfree(&g); 1515 globfree(&g);
1518 if (path1) 1516 free(path1);
1519 xfree(path1); 1517 free(path2);
1520 if (path2)
1521 xfree(path2);
1522 1518
1523 /* If an unignored error occurs in batch mode we should abort. */ 1519 /* If an unignored error occurs in batch mode we should abort. */
1524 if (err_abort && err != 0) 1520 if (err_abort && err != 0)
@@ -1628,8 +1624,8 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
1628 complete_display(list, 0); 1624 complete_display(list, 0);
1629 1625
1630 for (y = 0; list[y] != NULL; y++) 1626 for (y = 0; list[y] != NULL; y++)
1631 xfree(list[y]); 1627 free(list[y]);
1632 xfree(list); 1628 free(list);
1633 return count; 1629 return count;
1634 } 1630 }
1635 1631
@@ -1642,7 +1638,7 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
1642 list[count] = NULL; 1638 list[count] = NULL;
1643 1639
1644 if (count == 0) { 1640 if (count == 0) {
1645 xfree(list); 1641 free(list);
1646 return 0; 1642 return 0;
1647 } 1643 }
1648 1644
@@ -1652,8 +1648,8 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
1652 complete_display(list, 0); 1648 complete_display(list, 0);
1653 1649
1654 for (y = 0; list[y]; y++) 1650 for (y = 0; list[y]; y++)
1655 xfree(list[y]); 1651 free(list[y]);
1656 xfree(list); 1652 free(list);
1657 1653
1658 if (tmp != NULL) { 1654 if (tmp != NULL) {
1659 tmplen = strlen(tmp); 1655 tmplen = strlen(tmp);
@@ -1674,7 +1670,7 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
1674 if (y > 0 && el_insertstr(el, argterm) == -1) 1670 if (y > 0 && el_insertstr(el, argterm) == -1)
1675 fatal("el_insertstr failed."); 1671 fatal("el_insertstr failed.");
1676 } 1672 }
1677 xfree(tmp); 1673 free(tmp);
1678 } 1674 }
1679 1675
1680 return count; 1676 return count;
@@ -1738,7 +1734,7 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1738 if (tmp[tmplen] == '/') 1734 if (tmp[tmplen] == '/')
1739 pwdlen = tmplen + 1; /* track last seen '/' */ 1735 pwdlen = tmplen + 1; /* track last seen '/' */
1740 } 1736 }
1741 xfree(tmp); 1737 free(tmp);
1742 1738
1743 if (g.gl_matchc == 0) 1739 if (g.gl_matchc == 0)
1744 goto out; 1740 goto out;
@@ -1753,7 +1749,7 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1753 1749
1754 tmp2 = complete_ambiguous(file, g.gl_pathv, g.gl_matchc); 1750 tmp2 = complete_ambiguous(file, g.gl_pathv, g.gl_matchc);
1755 tmp = path_strip(tmp2, isabs ? NULL : remote_path); 1751 tmp = path_strip(tmp2, isabs ? NULL : remote_path);
1756 xfree(tmp2); 1752 free(tmp2);
1757 1753
1758 if (tmp == NULL) 1754 if (tmp == NULL)
1759 goto out; 1755 goto out;
@@ -1815,7 +1811,7 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1815 if (i > 0 && el_insertstr(el, ins) == -1) 1811 if (i > 0 && el_insertstr(el, ins) == -1)
1816 fatal("el_insertstr failed."); 1812 fatal("el_insertstr failed.");
1817 } 1813 }
1818 xfree(tmp); 1814 free(tmp);
1819 1815
1820 out: 1816 out:
1821 globfree(&g); 1817 globfree(&g);
@@ -1841,7 +1837,7 @@ complete(EditLine *el, int ch)
1841 memcpy(line, lf->buffer, cursor); 1837 memcpy(line, lf->buffer, cursor);
1842 line[cursor] = '\0'; 1838 line[cursor] = '\0';
1843 argv = makeargv(line, &carg, 1, &quote, &terminated); 1839 argv = makeargv(line, &carg, 1, &quote, &terminated);
1844 xfree(line); 1840 free(line);
1845 1841
1846 /* Get all the arguments on the line */ 1842 /* Get all the arguments on the line */
1847 len = lf->lastchar - lf->buffer; 1843 len = lf->lastchar - lf->buffer;
@@ -1853,7 +1849,7 @@ complete(EditLine *el, int ch)
1853 /* Ensure cursor is at EOL or a argument boundary */ 1849 /* Ensure cursor is at EOL or a argument boundary */
1854 if (line[cursor] != ' ' && line[cursor] != '\0' && 1850 if (line[cursor] != ' ' && line[cursor] != '\0' &&
1855 line[cursor] != '\n') { 1851 line[cursor] != '\n') {
1856 xfree(line); 1852 free(line);
1857 return ret; 1853 return ret;
1858 } 1854 }
1859 1855
@@ -1881,7 +1877,7 @@ complete(EditLine *el, int ch)
1881 ret = CC_REDISPLAY; 1877 ret = CC_REDISPLAY;
1882 } 1878 }
1883 1879
1884 xfree(line); 1880 free(line);
1885 return ret; 1881 return ret;
1886} 1882}
1887#endif /* USE_LIBEDIT */ 1883#endif /* USE_LIBEDIT */
@@ -1938,9 +1934,9 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
1938 snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); 1934 snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
1939 if (parse_dispatch_command(conn, cmd, 1935 if (parse_dispatch_command(conn, cmd,
1940 &remote_path, 1) != 0) { 1936 &remote_path, 1) != 0) {
1941 xfree(dir); 1937 free(dir);
1942 xfree(remote_path); 1938 free(remote_path);
1943 xfree(conn); 1939 free(conn);
1944 return (-1); 1940 return (-1);
1945 } 1941 }
1946 } else { 1942 } else {
@@ -1953,12 +1949,12 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
1953 1949
1954 err = parse_dispatch_command(conn, cmd, 1950 err = parse_dispatch_command(conn, cmd,
1955 &remote_path, 1); 1951 &remote_path, 1);
1956 xfree(dir); 1952 free(dir);
1957 xfree(remote_path); 1953 free(remote_path);
1958 xfree(conn); 1954 free(conn);
1959 return (err); 1955 return (err);
1960 } 1956 }
1961 xfree(dir); 1957 free(dir);
1962 } 1958 }
1963 1959
1964 setlinebuf(stdout); 1960 setlinebuf(stdout);
@@ -2016,8 +2012,8 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2016 if (err != 0) 2012 if (err != 0)
2017 break; 2013 break;
2018 } 2014 }
2019 xfree(remote_path); 2015 free(remote_path);
2020 xfree(conn); 2016 free(conn);
2021 2017
2022#ifdef USE_LIBEDIT 2018#ifdef USE_LIBEDIT
2023 if (el != NULL) 2019 if (el != NULL)