1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
Description: Stopped assuming readlink() result fit in PATH_MAX.
This avoid assuming something that might not be true for all file
systems, and get the code building on Hurd.
Author: Petter Reinholdtsen <pere@hungry.com>
Bug-Debian: https://bugs.debian.org/1103789
Forwarded: no
Last-Update: 2025-04-21
---
Index: python-grpc-tools-salsa/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc
===================================================================
--- python-grpc-tools-salsa.orig/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc 2025-04-21 15:55:06.384235266 +0200
+++ python-grpc-tools-salsa/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc 2025-04-21 15:55:30.052490544 +0200
@@ -189,6 +189,33 @@
return true;
}
+/* from
+ * <URL:https://buildsecurityin.us-cert.gov/bsi/articles/knowledge/coding/806-BSI.html>.
+ * via
+ * <URL:https://www.gnu.org/software/hurd//user/tlecarrour/porting_guide_for_dummies.html>
+*/
+static char *readlink_malloc(const char *filename)
+{
+ int size = 100;
+
+ while (1) {
+ char *buff = (char*)malloc(size);
+ if (buff == NULL)
+ return NULL;
+ int nchars = readlink(filename, buff, size);
+ if (nchars < 0) {
+ free(buff);
+ return NULL;
+ }
+ if (nchars < size) {
+ buff[nchars] = '\0';
+ return buff;
+ }
+ free (buff);
+ size *= 2;
+ }
+}
+
// Get the absolute path of this protoc binary.
bool GetProtocAbsolutePath(string* path) {
#ifdef _WIN32
@@ -205,11 +232,17 @@
len = strlen(buffer);
}
#else
- char buffer[PATH_MAX];
- int len = readlink("/proc/self/exe", buffer, PATH_MAX);
+ char *buffer = readlink_malloc("/proc/self/exe");
+ int len;
+ if (buffer)
+ len = strlen(buffer);
#endif
if (len > 0) {
path->assign(buffer, len);
+#if !defined(_WIN32) && !defined(__APPLE__)
+ free(buffer);
+ buffer = NULL;
+#endif /* !defined(_WIN32) && !defined(__APPLE__) */
return true;
} else {
return false;
|