Ignore:
Timestamp:
11/11/11 13:17:43 (19 months ago)
Author:
BrainSlayer
Message:

update proftp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/proftpd/contrib/mod_sftp/msg.c

    r14677 r17876  
    11/* 
    22 * ProFTPD - mod_sftp message format 
    3  * Copyright (c) 2008-2009 TJ Saunders 
     3 * Copyright (c) 2008-2011 TJ Saunders 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    1515 * You should have received a copy of the GNU General Public License 
    1616 * along with this program; if not, write to the Free Software 
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA. 
     17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 
    1818 * 
    1919 * As a special exemption, TJ Saunders and other respective copyright holders 
     
    2222 * source distribution. 
    2323 * 
    24  * $Id: msg.c,v 1.2 2009/02/13 23:41:19 castaglia Exp $ 
     24 * $Id: msg.c,v 1.7 2011/05/23 21:03:12 castaglia Exp $ 
    2525 */ 
    2626 
     
    3131#include "disconnect.h" 
    3232 
     33#ifdef HAVE_EXECINFO_H 
     34# include <execinfo.h> 
     35#endif 
     36 
    3337/* The scratch buffer used by getbuf() is a constant 8KB.  If the caller 
    3438 * requests a larger size than that, the request is fulfilled using the 
     
    3741static char msg_buf[8 * 1024]; 
    3842 
     43static 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 
    3977char *sftp_msg_getbuf(pool *p, size_t sz) { 
    4078  if (sz <= sizeof(msg_buf)) { 
     
    4684 
    4785char sftp_msg_read_byte(pool *p, char **buf, uint32_t *buflen) { 
    48   char byte; 
     86  char byte = 0; 
    4987 
    5088  (void) p; 
     
    5492      "message format error: unable to read byte (buflen = %lu)", 
    5593      (unsigned long) *buflen); 
     94    log_stacktrace(); 
    5695    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    5796  } 
     
    65104 
    66105int sftp_msg_read_bool(pool *p, char **buf, uint32_t *buflen) { 
    67   char bool; 
     106  char bool = 0; 
    68107 
    69108  (void) p; 
     
    78117char *sftp_msg_read_data(pool *p, char **buf, uint32_t *buflen, 
    79118    size_t datalen) { 
    80   char *data; 
     119  char *data = NULL; 
    81120 
    82121  if (*buflen < datalen) { 
    83122    (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(); 
    86126    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    87127  } 
     
    97137 
    98138uint32_t sftp_msg_read_int(pool *p, char **buf, uint32_t *buflen) { 
    99   uint32_t val; 
     139  uint32_t val = 0; 
    100140 
    101141  (void) p; 
     
    105145      "message format error: unable to read int (buflen = %lu)", 
    106146      (unsigned long) *buflen); 
     147    log_stacktrace(); 
    107148    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    108149  } 
     
    119160  BIGNUM *mpint = NULL; 
    120161  const unsigned char *data = NULL; 
    121   uint32_t datalen; 
     162  uint32_t datalen = 0; 
    122163 
    123164  datalen = sftp_msg_read_int(p, buf, buflen); 
     
    127168      "message format error: unable to read %lu bytes of mpint (buflen = %lu)", 
    128169      (unsigned long) datalen, (unsigned long) *buflen); 
     170    log_stacktrace(); 
    129171    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    130172  } 
     
    134176      "message format error: unable to handle mpint of %lu bytes", 
    135177      (unsigned long) datalen); 
     178    log_stacktrace(); 
    136179    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    137180  } 
     
    142185      "message format error: unable to read %lu bytes of mpint data", 
    143186      (unsigned long) datalen); 
     187    log_stacktrace(); 
    144188    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    145189  } 
     
    148192    (void) pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION, 
    149193      "message format error: negative mpint numbers not supported"); 
     194    log_stacktrace(); 
    150195    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    151196  } 
     
    156201      "message format error: unable to convert binary mpint: %s", 
    157202      sftp_crypto_get_errors()); 
     203    log_stacktrace(); 
    158204    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    159205  } 
     
    163209 
    164210char *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; 
    167213 
    168214  len = sftp_msg_read_int(p, buf, buflen); 
     
    177223      "message format error: unable to read %lu bytes of string data " 
    178224      "(buflen = %lu)", (unsigned long) len, (unsigned long) *buflen); 
     225    log_stacktrace(); 
    179226    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    180227  } 
     
    195242      "message format error: unable to write byte (buflen = %lu)", 
    196243      (unsigned long) *buflen); 
     244    log_stacktrace(); 
    197245    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    198246  } 
     
    215263  if (*buflen < datalen) { 
    216264    (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(); 
    219268    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    220269  } 
     
    232281      "message format error: unable to write int (buflen = %lu)", 
    233282      (unsigned long) *buflen); 
     283    log_stacktrace(); 
    234284    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    235285  } 
     
    243293void sftp_msg_write_mpint(char **buf, uint32_t *buflen, 
    244294    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; 
    248298 
    249299  if (BN_is_zero(mpint)) { 
     
    256306      "message format error: unable to write mpint (negative numbers not " 
    257307      "supported)"); 
     308    log_stacktrace(); 
    258309    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    259310  } 
     
    263314  if (*buflen < datalen) { 
    264315    (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(); 
    267319    SFTP_DISCONNECT_CONN(SFTP_SSH2_DISCONNECT_BY_APPLICATION, NULL); 
    268320  } 
     
    300352 
    301353void sftp_msg_write_string(char **buf, uint32_t *buflen, const char *str) { 
    302   uint32_t len; 
     354  uint32_t len = 0; 
    303355 
    304356  len = strlen(str); 
Note: See TracChangeset for help on using the changeset viewer.