Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From 4ffe00f1d9eac332d928f7dc01fe250dc32b1bb8 Mon Sep 17 00:00:00 2001 |
| 2 | From: Stan Cox <scox@redhat.com> |
| 3 | Date: Tue, 13 Feb 2018 22:38:03 -0500 |
| 4 | Subject: [PATCH] Fixes for gcc 8 |
| 5 | |
| 6 | * includes/sys/sdt.h (__SDT_COND_SIGNED): Add CT, cast type argument |
| 7 | |
| 8 | Author: Will Cohen <wcohen.redhat.com> |
| 9 | |
| 10 | * stap-serverd.cxx (generate_mok, handleRequest, handle_connection): |
| 11 | Catch format overflow |
| 12 | |
| 13 | * translate.cxx (translate_pass): Use ref in catch. |
| 14 | --- |
| 15 | Upstream-Status: Backport |
| 16 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 17 | |
| 18 | includes/sys/sdt.h | 20 ++++++++-------- |
| 19 | stap-serverd.cxx | 67 +++++++++++++++++++++++++++++++++++++++++++++++------- |
| 20 | translate.cxx | 2 +- |
| 21 | 3 files changed, 70 insertions(+), 19 deletions(-) |
| 22 | |
| 23 | diff --git a/includes/sys/sdt.h b/includes/sys/sdt.h |
| 24 | index 940f74483..c0c5a492c 100644 |
| 25 | --- a/includes/sys/sdt.h |
| 26 | +++ b/includes/sys/sdt.h |
| 27 | @@ -119,8 +119,8 @@ struct __sdt_type |
| 28 | |
| 29 | #define __SDT_ALWAYS_SIGNED(T) \ |
| 30 | template<> struct __sdt_type<T> { static const bool __sdt_signed = true; }; |
| 31 | -#define __SDT_COND_SIGNED(T) \ |
| 32 | -template<> struct __sdt_type<T> { static const bool __sdt_signed = ((T)(-1) < 1); }; |
| 33 | +#define __SDT_COND_SIGNED(T,CT) \ |
| 34 | +template<> struct __sdt_type<T> { static const bool __sdt_signed = ((CT)(-1) < 1); }; |
| 35 | __SDT_ALWAYS_SIGNED(signed char) |
| 36 | __SDT_ALWAYS_SIGNED(short) |
| 37 | __SDT_ALWAYS_SIGNED(int) |
| 38 | @@ -141,14 +141,14 @@ __SDT_ALWAYS_SIGNED(const volatile short) |
| 39 | __SDT_ALWAYS_SIGNED(const volatile int) |
| 40 | __SDT_ALWAYS_SIGNED(const volatile long) |
| 41 | __SDT_ALWAYS_SIGNED(const volatile long long) |
| 42 | -__SDT_COND_SIGNED(char) |
| 43 | -__SDT_COND_SIGNED(wchar_t) |
| 44 | -__SDT_COND_SIGNED(volatile char) |
| 45 | -__SDT_COND_SIGNED(volatile wchar_t) |
| 46 | -__SDT_COND_SIGNED(const char) |
| 47 | -__SDT_COND_SIGNED(const wchar_t) |
| 48 | -__SDT_COND_SIGNED(const volatile char) |
| 49 | -__SDT_COND_SIGNED(const volatile wchar_t) |
| 50 | +__SDT_COND_SIGNED(char, char) |
| 51 | +__SDT_COND_SIGNED(wchar_t, wchar_t) |
| 52 | +__SDT_COND_SIGNED(volatile char, char) |
| 53 | +__SDT_COND_SIGNED(volatile wchar_t, wchar_t) |
| 54 | +__SDT_COND_SIGNED(const char, char) |
| 55 | +__SDT_COND_SIGNED(const wchar_t, wchar_t) |
| 56 | +__SDT_COND_SIGNED(const volatile char, char) |
| 57 | +__SDT_COND_SIGNED(const volatile wchar_t, wchar_t) |
| 58 | #if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) |
| 59 | /* __SDT_COND_SIGNED(char16_t) */ |
| 60 | /* __SDT_COND_SIGNED(char32_t) */ |
| 61 | diff --git a/stap-serverd.cxx b/stap-serverd.cxx |
| 62 | index 7cf76c617..41f77ee9e 100644 |
| 63 | --- a/stap-serverd.cxx |
| 64 | +++ b/stap-serverd.cxx |
| 65 | @@ -1607,6 +1607,7 @@ generate_mok(string &mok_fingerprint) |
| 66 | char tmpdir[PATH_MAX] = { '\0' }; |
| 67 | string public_cert_path, private_cert_path, destdir; |
| 68 | mode_t old_umask; |
| 69 | + int retlen; |
| 70 | |
| 71 | mok_fingerprint.clear (); |
| 72 | |
| 73 | @@ -1631,7 +1632,14 @@ generate_mok(string &mok_fingerprint) |
| 74 | } |
| 75 | |
| 76 | // Make a temporary directory to store results in. |
| 77 | - snprintf (tmpdir, PATH_MAX, "%s/stap-server.XXXXXX", mok_path.c_str ()); |
| 78 | + retlen = snprintf (tmpdir, PATH_MAX, "%s/stap-server.XXXXXX", mok_path.c_str ()); |
| 79 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 80 | + { |
| 81 | + server_error (_F("Could not create %s name", "temporary directory")); |
| 82 | + tmpdir[0] = '\0'; |
| 83 | + goto cleanup; |
| 84 | + } |
| 85 | + |
| 86 | if (mkdtemp (tmpdir) == NULL) |
| 87 | { |
| 88 | server_error (_F("Could not create temporary directory %s: %s", tmpdir, |
| 89 | @@ -1704,6 +1712,7 @@ handleRequest (const string &requestDirName, const string &responseDirName, stri |
| 90 | unsigned u; |
| 91 | unsigned i; |
| 92 | FILE* f; |
| 93 | + int retlen; |
| 94 | |
| 95 | // Save the server version. Do this early, so the client knows what version of the server |
| 96 | // it is dealing with, even if the request is not fully completed. |
| 97 | @@ -1782,7 +1791,12 @@ handleRequest (const string &requestDirName, const string &responseDirName, stri |
| 98 | struct stat st; |
| 99 | char *arg; |
| 100 | |
| 101 | - snprintf (stapargfile, PATH_MAX, "%s/argv%d", requestDirName.c_str (), i); |
| 102 | + retlen = snprintf (stapargfile, PATH_MAX, "%s/argv%d", requestDirName.c_str (), i); |
| 103 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 104 | + { |
| 105 | + server_error (_F("Error creating %s name", "path")); |
| 106 | + return; |
| 107 | + } |
| 108 | |
| 109 | rc = stat(stapargfile, & st); |
| 110 | if (rc) break; |
| 111 | @@ -1888,7 +1902,15 @@ handleRequest (const string &requestDirName, const string &responseDirName, stri |
| 112 | { |
| 113 | glob_t globber; |
| 114 | char pattern[PATH_MAX]; |
| 115 | - snprintf (pattern, PATH_MAX, "%s/*.ko", new_staptmpdir.c_str()); |
| 116 | + int retlen; |
| 117 | + |
| 118 | + retlen = snprintf (pattern, PATH_MAX, "%s/*.ko", new_staptmpdir.c_str()); |
| 119 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 120 | + { |
| 121 | + server_error (_F("Error creating %s name", "pattern")); |
| 122 | + return; |
| 123 | + } |
| 124 | + |
| 125 | rc = glob (pattern, GLOB_ERR, NULL, &globber); |
| 126 | if (rc) |
| 127 | server_error (_F("Unable to find a module in %s", new_staptmpdir.c_str())); |
| 128 | @@ -2164,6 +2186,7 @@ handle_connection (void *arg) |
| 129 | copy for each connection.*/ |
| 130 | vector<string> argv; |
| 131 | PRInt32 bytesRead; |
| 132 | + int retlen; |
| 133 | |
| 134 | /* Detatch to avoid a memory leak */ |
| 135 | if(max_threads > 0) |
| 136 | @@ -2213,7 +2236,13 @@ handle_connection (void *arg) |
| 137 | #endif |
| 138 | |
| 139 | secStatus = SECFailure; |
| 140 | - snprintf(tmpdir, PATH_MAX, "%s/stap-server.XXXXXX", getenv("TMPDIR") ?: "/tmp"); |
| 141 | + retlen = snprintf(tmpdir, PATH_MAX, "%s/stap-server.XXXXXX", getenv("TMPDIR") ?: "/tmp"); |
| 142 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 143 | + { |
| 144 | + server_error (_F("Error creating %s name", "temporary directory")); |
| 145 | + tmpdir[0]=0; /* prevent /bin/rm */ |
| 146 | + goto cleanup; |
| 147 | + } |
| 148 | rc1 = mkdtemp(tmpdir); |
| 149 | if (! rc1) |
| 150 | { |
| 151 | @@ -2223,9 +2252,20 @@ handle_connection (void *arg) |
| 152 | } |
| 153 | |
| 154 | /* Create a temporary files names and directories. */ |
| 155 | - snprintf (requestFileName, PATH_MAX, "%s/request.zip", tmpdir); |
| 156 | + retlen = snprintf (requestFileName, PATH_MAX, "%s/request.zip", tmpdir); |
| 157 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 158 | + { |
| 159 | + server_error (_F("Error creating %s name", "request.zip path")); |
| 160 | + goto cleanup; |
| 161 | + } |
| 162 | + |
| 163 | + retlen = snprintf (requestDirName, PATH_MAX, "%s/request", tmpdir); |
| 164 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 165 | + { |
| 166 | + server_error (_F("Error creating %s name", "request directory path")); |
| 167 | + goto cleanup; |
| 168 | + } |
| 169 | |
| 170 | - snprintf (requestDirName, PATH_MAX, "%s/request", tmpdir); |
| 171 | rc = mkdir(requestDirName, 0700); |
| 172 | if (rc) |
| 173 | { |
| 174 | @@ -2233,7 +2273,13 @@ handle_connection (void *arg) |
| 175 | goto cleanup; |
| 176 | } |
| 177 | |
| 178 | - snprintf (responseDirName, PATH_MAX, "%s/response", tmpdir); |
| 179 | + retlen = snprintf (responseDirName, PATH_MAX, "%s/response", tmpdir); |
| 180 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 181 | + { |
| 182 | + server_error (_F("Error creating %s name", "response directory path")); |
| 183 | + goto cleanup; |
| 184 | + } |
| 185 | + |
| 186 | rc = mkdir(responseDirName, 0700); |
| 187 | if (rc) |
| 188 | { |
| 189 | @@ -2243,7 +2289,12 @@ handle_connection (void *arg) |
| 190 | // Set this early, since it gets used for errors to be returned to the client. |
| 191 | stapstderr = string(responseDirName) + "/stderr"; |
| 192 | |
| 193 | - snprintf (responseFileName, PATH_MAX, "%s/response.zip", tmpdir); |
| 194 | + retlen = snprintf (responseFileName, PATH_MAX, "%s/response.zip", tmpdir); |
| 195 | + if (retlen < 0 || retlen >= PATH_MAX) |
| 196 | + { |
| 197 | + server_error (_F("Error creating %s name", "response.zip path")); |
| 198 | + goto cleanup; |
| 199 | + } |
| 200 | |
| 201 | /* Read data from the socket. |
| 202 | * If the user is requesting/requiring authentication, authenticate |
| 203 | diff --git a/translate.cxx b/translate.cxx |
| 204 | index 1240a80ec..4ade06fdd 100644 |
| 205 | --- a/translate.cxx |
| 206 | +++ b/translate.cxx |
| 207 | @@ -7860,7 +7860,7 @@ translate_pass (systemtap_session& s) |
| 208 | if (versions.size() >= 3 && s.verbose > 1) |
| 209 | clog << _F("ignoring extra parts of compat version: %s", s.compatible.c_str()) << endl; |
| 210 | } |
| 211 | - catch (const runtime_error) |
| 212 | + catch (const runtime_error&) |
| 213 | { |
| 214 | throw SEMANTIC_ERROR(_F("parse error in compatibility version: %s", s.compatible.c_str())); |
| 215 | } |