Re: [bug #30065] MAXPATHLEN breaks builds on GNU/Hurd

Francis Russell <[email protected]>
Newsgroups gmane.comp.version-control.monotone.devel
Message-ID <[email protected]>
On 28/03/12 09:27, Richard Levitte wrote:

> What did you have in mind?

To be honest, I think the big scary warning put me off more than the
patch itself. Although I do note that the patch appears to use  variable
length stack allocated arrays which aren't valid in C++.

I guess I was thinking of something more like the attached (again
untested), with the idea that the get_current_working_dir()
implementations in both src/{unix,win32}/fs.cc could both use it since
they both build strings from the buffer returned by getcwd (and the
majority of added code would no longer be dead). I don't have much idea
on monotone's policy on dynamic memory allocation and error handing for
failures of it though.

Anyway, I was hoping HURD fix would be a mainly non-disruptive change
that wasn't possibly introducing other bugs. Since the code is dead,
replacing MAXPATHLEN with a hard coded value as in
src/{unix,win32}/fs.cc is probably better unless there is an intention
to remove some of the hard-coded limits on path lengths.

Francis

_______________________________________________
Monotone-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/monotone-devel
mtn.diff (text/x-patch, 1.8 KB)
#
# old_revision [abed170b1da27108dc8dc5fb33729e3e9270f6f6]
#
# patch "src/netxx/serverbase.cxx"
#  from [7a9b465ce4b0b02cb8ff126acf86d3896b4eb456]
#    to [998f3d4723ced8d243091e416d01ab94ec2b8ffb]
#
============================================================
--- src/netxx/serverbase.cxx	7a9b465ce4b0b02cb8ff126acf86d3896b4eb456
+++ src/netxx/serverbase.cxx	998f3d4723ced8d243091e416d01ab94ec2b8ffb
@@ -44,6 +44,8 @@
 #include "probeinfo.h"
 #include "socket.h"
 
+#include <cerrno>
+
 // standard includes
 #include <map>
 #include <vector>
@@ -59,6 +61,27 @@ namespace 
 	    void operator() (const std::string &file)
 	    { unlink(file.c_str()); }
 	};
+
+        bool get_cwd(std::string& out)
+        {
+          static const int initial_buffer_size = 1024;
+          int current_buffer_size = initial_buffer_size;
+
+          do
+          {
+            std::vector<char> buffer(current_buffer_size);
+            if (getcwd(&buffer[0], buffer.size()) != NULL)
+            {
+              out = &buffer[0];
+              return true;
+            }
+
+            current_buffer_size *= 2;
+          }
+          while(errno == ERANGE);
+
+          return false;
+        }
 #   endif
 }
 //####################################################################
@@ -167,10 +190,9 @@ void Netxx::ServerBase::bind_to(const Ad
 		if (saun->sun_path[0] == '/') {
 		    files_.push_back(saun->sun_path);
 		} else {
-		    char buffer[MAXPATHLEN];
-
-		    if (getcwd(buffer, sizeof(buffer))) {
- 			std::string fullpath = buffer; fullpath += '/'; fullpath += saun->sun_path;
+                    std::string fullpath;
+		    if (get_cwd(fullpath)) {
+ 			fullpath += '/'; fullpath += saun->sun_path;
 			files_.push_back(fullpath);
 		    } else {
 			files_.push_back(saun->sun_path);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.