[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#933015: libssh FTBFS on hurd: unconditional usage of PATH_MAX



Hi,

Am Montag, den 29.07.2019, 18:49 +0200 schrieb Guillem Jover:
> Hi!
> 
> On Thu, 2019-07-25 at 20:36:31 +0200, Paul Sonnenschein wrote:
> > [...]
> I'd probably just unconditionally set the value and avoid PATH_MAX
> completely.

See appendix libssh-path-max-no-path-max.patch. This version does not
use PATH_MAX as a size hint.

> > [...]
> 
> JFTR, there's also the getcwd(NULL, 0) extension which is supported
> by
> GNU and BSD systems, at least. Or the explicit GNU specific function
> get_current_dir_name(), But that would need some kind of
> configuration
> check, and some fallback code anyway.

Like libssh-path-max-no-path-max.patch? The appended version does not
use CMake, but only checks for __GLIBC__, which of course could be
changed.

> > [...]
> 
> Thanks,
> Guillem

Sorry for taking so long to react, I was busy during the last few
weeks.

Thanks,
	Paul Sonnenschein
Subject: Fix unconditional use of PATH_MAX
Author: Paul Sonnenschein <paul@sonnenschein.ruhr>
Bug-Debian: https://bugs.debian.org/933015
diff --git a/tests/torture.c b/tests/torture.c
index 772942c..b4188f1 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -1030,6 +1030,12 @@ char *torture_get_current_working_dir(void)
     char *cwd = NULL;
     char *result = NULL;
 
+#ifdef __GLIBC__
+
+    cwd = getcwd(NULL, 0);
+
+#else /* ! __GLIBC__ */
+
     cwd = (char *)malloc(PATH_MAX + 1);
     if (cwd == NULL) {
         goto end;
@@ -1042,6 +1048,8 @@ char *torture_get_current_working_dir(void)
         goto end;
     }
 
+#endif /* ! __GLIBC__ */
+
 end:
     return cwd;
 }
Subject: Fix unconditional use of PATH_MAX
Author: Paul Sonnenschein <paul@sonnenschein.ruhr>
Bug-Debian: https://bugs.debian.org/933015
diff --git a/tests/torture.c b/tests/torture.c
index 772942c..08b126b 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -1029,17 +1029,21 @@ char *torture_get_current_working_dir(void)
 
     char *cwd = NULL;
     char *result = NULL;
+    size_t bufsize;
 
-    cwd = (char *)malloc(PATH_MAX + 1);
-    if (cwd == NULL) {
-        goto end;
-    }
+    bufsize = 4095;
+    for ( ; result == NULL; bufsize *= 2) {
+        cwd = (char *)realloc(cwd, bufsize + 1);
+        if (cwd == NULL) {
+            goto end;
+        }
 
-    result = getcwd(cwd, PATH_MAX);
+        result = getcwd(cwd, bufsize);
 
-    if (result == NULL) {
-        SAFE_FREE(cwd);
-        goto end;
+        if (result == NULL && errno != ERANGE) {
+            SAFE_FREE(cwd);
+            goto end;
+        }
     }
 
 end:

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: