cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: PATH_MAX

From: James Housley <jim_at_thehousleys.net>
Date: Mon, 18 Jun 2007 18:31:01 -0400

On Jun 18, 2007, at 7:14 AM, Daniel Stenberg wrote:

> Hi James,
>
> The PATH_MAX usage in lib/urldata.h still breaks builds and I
> hesitate to release until we have this sorted.
>
> Also, I've taken a look at this and I think we should reconsider
> the use of this define:
>
> It is by default set to 4096 on many systems, and having two
> variables of that size by default in a struct is needlessly gonna
> add some 8K of memory use for every single connection (for libcurls
> with SSH-capabilities enabled). I think we should rather malloc-on-
> demand instead.
>
> I think the asprintf() function should come handy for this.
>
> So what do you think about this?

Here is what I have come up with. It passes all tests and looks
right to me, but I would like another set of eyes this close to release.

Jim

Index: lib/ssh.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/ssh.c,v
retrieving revision 1.48
diff -u -r1.48 ssh.c
--- lib/ssh.c 16 Jun 2007 16:58:02 -0000 1.48
+++ lib/ssh.c 18 Jun 2007 22:28:52 -0000
@@ -318,8 +318,8 @@
        /* The fingerprint points to static storage (!), don't free()
it. */
        infof(data, "Fingerprint: ");
- for (i = 0; i < 16; i++) {
- infof(data, "%02X ", (unsigned char) fingerprint[i]);
+ for (rc = 0; rc < 16; rc++) {
+ infof(data, "%02X ", (unsigned char) fingerprint[rc]);
        }
        infof(data, "\n");
#endif /* CURL_LIBSSH2_DEBUG */
@@ -369,24 +369,21 @@
            (strstr(sshc->authlist, "publickey") != NULL)) {
          char *home;
- sshc->rsa_pub[0] = sshc->rsa[0] = '\0';
+ sshc->rsa_pub = sshc->rsa = NULL;
          /* To ponder about: should really the lib be messing about
with the
             HOME environment variable etc? */
          home = curl_getenv("HOME");
          if (data->set.ssh_public_key)
- snprintf(sshc->rsa_pub, sizeof(sshc->rsa_pub), "%s",
- data->set.ssh_public_key);
+ sshc->rsa_pub = aprintf("%s", data->set.ssh_public_key);
          else if (home)
- snprintf(sshc->rsa_pub, sizeof(sshc->rsa_pub), "%s/.ssh/
id_dsa.pub",
- home);
+ sshc->rsa_pub = aprintf("%s/.ssh/id_dsa.pub", home);
          if (data->set.ssh_private_key)
- snprintf(sshc->rsa, sizeof(sshc->rsa), "%s",
- data->set.ssh_private_key);
+ sshc->rsa = aprintf("%s", data->set.ssh_private_key);
          else if (home)
- snprintf(sshc->rsa, sizeof(sshc->rsa), "%s/.ssh/id_dsa",
home);
+ sshc->rsa = aprintf("%s/.ssh/id_dsa", home);
          sshc->passphrase = data->set.key_passwd;
          if (!sshc->passphrase)
@@ -394,12 +391,19 @@
          curl_free(home);
- infof(conn->data, "Using ssh public key file %s\n", sshc-
>rsa_pub);
- infof(conn->data, "Using ssh private key file %s\n", sshc-
>rsa);
+ if (sshc->rsa_pub) {
+ infof(conn->data, "Using ssh public key file %s\n", sshc-
>rsa_pub);
+ }
+ if (sshc->rsa) {
+ infof(conn->data, "Using ssh private key file %s\n", sshc-
>rsa);
+ }
- if (sshc->rsa_pub[0]) {
+ if (sshc->rsa_pub && sshc->rsa_pub) {
            state(conn, SSH_AUTH_PKEY);
          } else {
+ curl_free(sshc->rsa_pub);
+ curl_free(sshc->rsa);
+
            state(conn, SSH_AUTH_PASS_INIT);
          }
        } else {
@@ -416,7 +420,11 @@
        if (rc == LIBSSH2_ERROR_EAGAIN) {
          break;
        }
- else if (rc == 0) {
+
+ curl_free(sshc->rsa_pub);
+ curl_free(sshc->rsa);
+
+ if (rc == 0) {
          sshc->authed = TRUE;
          infof(conn->data, "Initialized SSH public key authentication
\n");
          state(conn, SSH_AUTH_DONE);
Index: lib/urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.332
diff -u -r1.332 urldata.h
--- lib/urldata.h 12 Jun 2007 21:32:45 -0000 1.332
+++ lib/urldata.h 18 Jun 2007 22:28:52 -0000
@@ -451,8 +451,8 @@
struct ssh_conn {
    const char *authlist; /* List of auth. methods, managed by
libssh2 */
    const char *passphrase;
- char rsa_pub[PATH_MAX];
- char rsa[PATH_MAX];
+ char *rsa_pub;
+ char *rsa;
    bool authed;
    sshstate state; /* always use ssh.c:state() to change state! */
    CURLcode actualCode; /* the actual error code */

--
/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
                      http://www.FreeBSD.org     The Power to Serve
jim@TheHousleys.Net  http://www.TheHousleys.net
---------------------------------------------------------------------
The wise man built his network upon Un*x.
     The foolish man built his network upon Windows.
Received on 2007-06-19