Changeset 17876 for src/router/proftpd/contrib/mod_sftp/msg.c
- Timestamp:
- 11/11/11 13:17:43 (19 months ago)
- File:
-
- 1 edited
-
src/router/proftpd/contrib/mod_sftp/msg.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/router/proftpd/contrib/mod_sftp/msg.c
r14677 r17876 1 1 /* 2 2 * ProFTPD - mod_sftp message format 3 * Copyright (c) 2008-20 09TJ Saunders3 * Copyright (c) 2008-2011 TJ Saunders 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 15 15 * You should have received a copy of the GNU General Public License 16 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 5 9 Temple Place, Suite 330, Boston, MA 02111-1307, USA.17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 18 * 19 19 * As a special exemption, TJ Saunders and other respective copyright holders … … 22 22 * source distribution. 23 23 * 24 * $Id: msg.c,v 1. 2 2009/02/13 23:41:19castaglia Exp $24 * $Id: msg.c,v 1.7 2011/05/23 21:03:12 castaglia Exp $ 25 25 */ 26 26 … … 31 31 #include "disconnect.h" 32 32 33 #ifdef HAVE_EXECINFO_H 34 # include <execinfo.h> 35 #endif 36 33 37 /* The scratch buffer used by getbuf() is a constant 8KB. If the caller 34 38 * requests a larger size than that, the request is fulfilled using the … … 37 41 static char msg_buf[8 * 1024]; 38 42 43 static void log_stacktrace(void) { 44 #if defined(HAVE_EXECINFO_H) && \ 45 defined(HAVE_BACKTRACE) && \ 46 defined(HAVE_BACKTRACE_SYMBOLS) 47 void *trace[PR_TUNABLE_CALLER_DEPTH]; 48 char **strings; 49 size_t tracesz; 50 51 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 52 "-----BEGIN STACK TRACE-----"); 53 54 tracesz = backtrace(trace, PR_TUNABLE_CALLER_DEPTH); 55 strings = backtrace_symbols(trace, tracesz); 56 if (strings != NULL) { 57 register unsigned int i; 58 59 for (i = 1; i < tracesz; i++) { 60 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 61 "[%u] %s", i-1, strings[i]); 62 } 63 64 /* Prevent memory leaks. */ 65 free(strings); 66 67 } else { 68 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 69 "error obtaining stacktrace symbols: %s", strerror(errno)); 70 } 71 72 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 73 "-----END STACK TRACE-----"); 74 #endif 75 } 76 39 77 char *sftp_msg_getbuf(pool *p, size_t sz) { 40 78 if (sz <= sizeof(msg_buf)) { … … 46 84 47 85 char sftp_msg_read_byte(pool *p, char **buf, uint32_t *buflen) { 48 char byte ;86 char byte = 0; 49 87 50 88 (void) p; … … 54 92 "message format error: unable to read byte (buflen = %lu)", 55 93 (unsigned long) *buflen); 94 log_stacktrace(); 56 95 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 57 96 } … … 65 104 66 105 int sftp_msg_read_bool(pool *p, char **buf, uint32_t *buflen) { 67 char bool ;106 char bool = 0; 68 107 69 108 (void) p; … … 78 117 char *sftp_msg_read_data(pool *p, char **buf, uint32_t *buflen, 79 118 size_t datalen) { 80 char *data ;119 char *data = NULL; 81 120 82 121 if (*buflen < datalen) { 83 122 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 84 "message format error: unable to read %u bytes of raw data " 85 "(buflen = %lu)", (unsigned int) datalen, (unsigned long) *buflen); 123 "message format error: unable to read %lu bytes of raw data " 124 "(buflen = %lu)", (unsigned long) datalen, (unsigned long) *buflen); 125 log_stacktrace(); 86 126 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 87 127 } … … 97 137 98 138 uint32_t sftp_msg_read_int(pool *p, char **buf, uint32_t *buflen) { 99 uint32_t val ;139 uint32_t val = 0; 100 140 101 141 (void) p; … … 105 145 "message format error: unable to read int (buflen = %lu)", 106 146 (unsigned long) *buflen); 147 log_stacktrace(); 107 148 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 108 149 } … … 119 160 BIGNUM *mpint = NULL; 120 161 const unsigned char *data = NULL; 121 uint32_t datalen ;162 uint32_t datalen = 0; 122 163 123 164 datalen = sftp_msg_read_int(p, buf, buflen); … … 127 168 "message format error: unable to read %lu bytes of mpint (buflen = %lu)", 128 169 (unsigned long) datalen, (unsigned long) *buflen); 170 log_stacktrace(); 129 171 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 130 172 } … … 134 176 "message format error: unable to handle mpint of %lu bytes", 135 177 (unsigned long) datalen); 178 log_stacktrace(); 136 179 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 137 180 } … … 142 185 "message format error: unable to read %lu bytes of mpint data", 143 186 (unsigned long) datalen); 187 log_stacktrace(); 144 188 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 145 189 } … … 148 192 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 149 193 "message format error: negative mpint numbers not supported"); 194 log_stacktrace(); 150 195 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 151 196 } … … 156 201 "message format error: unable to convert binary mpint: %s", 157 202 sftp_crypto_get_errors()); 203 log_stacktrace(); 158 204 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 159 205 } … … 163 209 164 210 char *sftp_msg_read_string(pool *p, char **buf, uint32_t *buflen) { 165 uint32_t len ;166 char *str ;211 uint32_t len = 0; 212 char *str = NULL; 167 213 168 214 len = sftp_msg_read_int(p, buf, buflen); … … 177 223 "message format error: unable to read %lu bytes of string data " 178 224 "(buflen = %lu)", (unsigned long) len, (unsigned long) *buflen); 225 log_stacktrace(); 179 226 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 180 227 } … … 195 242 "message format error: unable to write byte (buflen = %lu)", 196 243 (unsigned long) *buflen); 244 log_stacktrace(); 197 245 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 198 246 } … … 215 263 if (*buflen < datalen) { 216 264 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 217 "message format error: unable to write %u bytes of raw data " 218 "(buflen = %lu)", (unsigned int) datalen, (unsigned long) *buflen); 265 "message format error: unable to write %lu bytes of raw data " 266 "(buflen = %lu)", (unsigned long) datalen, (unsigned long) *buflen); 267 log_stacktrace(); 219 268 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 220 269 } … … 232 281 "message format error: unable to write int (buflen = %lu)", 233 282 (unsigned long) *buflen); 283 log_stacktrace(); 234 284 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 235 285 } … … 243 293 void sftp_msg_write_mpint(char **buf, uint32_t *buflen, 244 294 const BIGNUM *mpint) { 245 unsigned char *data ;246 size_t datalen ;247 int res ;295 unsigned char *data = NULL; 296 size_t datalen = 0; 297 int res = 0; 248 298 249 299 if (BN_is_zero(mpint)) { … … 256 306 "message format error: unable to write mpint (negative numbers not " 257 307 "supported)"); 308 log_stacktrace(); 258 309 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 259 310 } … … 263 314 if (*buflen < datalen) { 264 315 (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 265 "message format error: unable to write %u bytes of mpint (buflen = %lu)", 266 (unsigned int) datalen, (unsigned long) *buflen); 316 "message format error: unable to write %lu bytes of mpint (buflen = %lu)", 317 (unsigned long) datalen, (unsigned long) *buflen); 318 log_stacktrace(); 267 319 SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 268 320 } … … 300 352 301 353 void sftp_msg_write_string(char **buf, uint32_t *buflen, const char *str) { 302 uint32_t len ;354 uint32_t len = 0; 303 355 304 356 len = strlen(str);
Note: See TracChangeset
for help on using the changeset viewer.
