Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libtelnet/encrypt.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libtelnet/encrypt.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.14 retrieving revision 1.14.34.1 diff -u -p -r1.14 -r1.14.34.1 --- src/lib/libtelnet/encrypt.c 2007/01/17 23:24:22 1.14 +++ src/lib/libtelnet/encrypt.c 2012/04/17 00:05:33 1.14.34.1 @@ -1,4 +1,4 @@ -/* $NetBSD: encrypt.c,v 1.14 2007/01/17 23:24:22 hubertf Exp $ */ +/* $NetBSD: encrypt.c,v 1.14.34.1 2012/04/17 00:05:33 yamt Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -33,7 +33,7 @@ #if 0 static char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95"; #else -__RCSID("$NetBSD: encrypt.c,v 1.14 2007/01/17 23:24:22 hubertf Exp $"); +__RCSID("$NetBSD: encrypt.c,v 1.14.34.1 2012/04/17 00:05:33 yamt Exp $"); #endif /* not lint */ /* @@ -126,7 +126,7 @@ static Encryptions encryptions[] = { ofb64_keyid, ofb64_printsub }, #endif /* DES_ENCRYPTION */ - { 0, }, + { .name = 0 }, }; static unsigned char str_send[64] = { IAC, SB, TELOPT_ENCRYPT, @@ -135,9 +135,8 @@ static unsigned char str_suplen = 0; static unsigned char str_start[72] = { IAC, SB, TELOPT_ENCRYPT }; static unsigned char str_end[] = { IAC, SB, TELOPT_ENCRYPT, 0, IAC, SE }; - Encryptions * -findencryption(type) - int type; +Encryptions * +findencryption(int type) { Encryptions *ep = encryptions; @@ -148,9 +147,8 @@ findencryption(type) return(ep->type ? ep : 0); } - Encryptions * -finddecryption(type) - int type; +Encryptions * +finddecryption(int type) { Encryptions *ep = encryptions; @@ -174,10 +172,8 @@ static struct key_info { { { 0 }, 0, DIR_DECRYPT, &decrypt_mode, finddecryption }, }; - void -encrypt_init(name, server) - const char *name; - int server; +void +encrypt_init(const char *name, int server) { Encryptions *ep = encryptions; @@ -212,8 +208,8 @@ encrypt_init(name, server) str_send[str_suplen++] = SE; } - void -encrypt_list_types() +void +encrypt_list_types(void) { Encryptions *ep = encryptions; @@ -224,9 +220,8 @@ encrypt_list_types() } } - int -EncryptEnable(type, mode) - char *type, *mode; +int +EncryptEnable(char *type, char *mode) { if (isprefix(type, "help") || isprefix(type, "?")) { printf("Usage: encrypt enable [input|output]\n"); @@ -238,9 +233,8 @@ EncryptEnable(type, mode) return(0); } - int -EncryptDisable(type, mode) - char *type, *mode; +int +EncryptDisable(char *type, char *mode) { register Encryptions *ep; int ret = 0; @@ -272,10 +266,8 @@ EncryptDisable(type, mode) return(ret); } - int -EncryptType(type, mode) - char *type; - char *mode; +int +EncryptType(char *type, char *mode) { register Encryptions *ep; int ret = 0; @@ -305,9 +297,8 @@ EncryptType(type, mode) return(ret); } - int -EncryptStart(mode) - char *mode; +int +EncryptStart(char *mode) { register int ret = 0; if (mode) { @@ -327,8 +318,8 @@ EncryptStart(mode) return(ret); } - int -EncryptStartInput() +int +EncryptStartInput(void) { if (decrypt_mode) { encrypt_send_request_start(); @@ -338,8 +329,8 @@ EncryptStartInput() return(0); } - int -EncryptStartOutput() +int +EncryptStartOutput(void) { if (encrypt_mode) { encrypt_start_output(encrypt_mode); @@ -349,9 +340,8 @@ EncryptStartOutput() return(0); } - int -EncryptStop(mode) - char *mode; +int +EncryptStop(char *mode) { int ret = 0; if (mode) { @@ -371,22 +361,22 @@ EncryptStop(mode) return(ret); } - int -EncryptStopInput() +int +EncryptStopInput(void) { encrypt_send_request_end(); return(1); } - int -EncryptStopOutput() +int +EncryptStopOutput(void) { encrypt_send_end(); return(1); } - void -encrypt_display() +void +encrypt_display(void) { if (encrypt_output) printf("Currently encrypting output with %s\r\n", @@ -396,8 +386,8 @@ encrypt_display() ENCTYPE_NAME(decrypt_mode)); } - int -EncryptStatus() +int +EncryptStatus(void) { if (encrypt_output) printf("Currently encrypting output with %s\r\n", @@ -418,8 +408,8 @@ EncryptStatus() return 1; } - void -encrypt_send_support() +void +encrypt_send_support(void) { if (str_suplen) { /* @@ -435,9 +425,8 @@ encrypt_send_support() } } - int -EncryptDebug(on) - int on; +int +EncryptDebug(int on) { if (on < 0) encrypt_debug_mode ^= 1; @@ -448,9 +437,8 @@ EncryptDebug(on) return(1); } - int -EncryptVerbose(on) - int on; +int +EncryptVerbose(int on) { if (on < 0) encrypt_verbose ^= 1; @@ -461,9 +449,8 @@ EncryptVerbose(on) return(1); } - int -EncryptAutoEnc(on) - int on; +int +EncryptAutoEnc(int on) { encrypt_auto(on); printf("Automatic encryption of output is %s\r\n", @@ -471,9 +458,8 @@ EncryptAutoEnc(on) return(1); } - int -EncryptAutoDec(on) - int on; +int +EncryptAutoDec(int on) { decrypt_auto(on); printf("Automatic decryption of input is %s\r\n", @@ -484,10 +470,8 @@ EncryptAutoDec(on) /* * Called when ENCRYPT SUPPORT is received. */ - void -encrypt_support(typelist, cnt) - unsigned char *typelist; - int cnt; +void +encrypt_support(unsigned char *typelist, int cnt) { register int type, use_type = 0; Encryptions *ep; @@ -526,10 +510,8 @@ encrypt_support(typelist, cnt) } } - void -encrypt_is(data, cnt) - unsigned char *data; - int cnt; +void +encrypt_is(unsigned char *data, int cnt) { Encryptions *ep; register int type, ret; @@ -572,10 +554,8 @@ encrypt_is(data, cnt) } } - void -encrypt_reply(data, cnt) - unsigned char *data; - int cnt; +void +encrypt_reply(unsigned char *data, int cnt) { Encryptions *ep; register int ret, type; @@ -622,10 +602,8 @@ encrypt_reply(data, cnt) /* * Called when a ENCRYPT START command is received. */ - void -encrypt_start(data, cnt) - unsigned char *data; - int cnt; +void +encrypt_start(unsigned char *data, int cnt) { Encryptions *ep; @@ -660,10 +638,8 @@ encrypt_start(data, cnt) } } - void -encrypt_session_key(key, server) - Session_Key *key; - int server; +void +encrypt_session_key(Session_Key *key, int server) { Encryptions *ep = encryptions; @@ -685,8 +661,8 @@ encrypt_session_key(key, server) /* * Called when ENCRYPT END is received. */ - void -encrypt_end() +void +encrypt_end(void) { decrypt_input = 0; if (encrypt_debug_mode) @@ -698,8 +674,8 @@ encrypt_end() /* * Called when ENCRYPT REQUEST-END is received. */ - void -encrypt_request_end() +void +encrypt_request_end(void) { encrypt_send_end(); } @@ -710,10 +686,8 @@ encrypt_request_end() * other side wants us to start encrypting data as soon as we * can. */ - void -encrypt_request_start(data, cnt) - unsigned char *data; - int cnt; +void +encrypt_request_start(unsigned char *data, int cnt) { if (encrypt_mode == 0) { if (Server) @@ -725,27 +699,20 @@ encrypt_request_start(data, cnt) static unsigned char str_keyid[(MAXKEYLEN*2)+5] = { IAC, SB, TELOPT_ENCRYPT }; - void -encrypt_enc_keyid(keyid, len) - unsigned char *keyid; - int len; +void +encrypt_enc_keyid(unsigned char *keyid, int len) { encrypt_keyid(&ki[1], keyid, len); } - void -encrypt_dec_keyid(keyid, len) - unsigned char *keyid; - int len; +void +encrypt_dec_keyid(unsigned char *keyid, int len) { encrypt_keyid(&ki[0], keyid, len); } void -encrypt_keyid(kp, keyid, len) - struct key_info *kp; - unsigned char *keyid; - int len; +encrypt_keyid(struct key_info *kp, unsigned char *keyid, int len) { Encryptions *ep; int dir = kp->dir; @@ -765,6 +732,8 @@ encrypt_keyid(kp, keyid, len) if (ep->keyid) (void)(*ep->keyid)(dir, kp->keyid, &kp->keylen); + } else if ((size_t)len > sizeof(kp->keyid)) { + return; } else if ((len != kp->keylen) || (memcmp(keyid, kp->keyid, len) != 0)) { /* @@ -785,12 +754,8 @@ encrypt_keyid(kp, keyid, len) encrypt_send_keyid(dir, kp->keyid, kp->keylen, 0); } - void -encrypt_send_keyid(dir, keyid, keylen, saveit) - int dir; - unsigned char *keyid; - int keylen; - int saveit; +void +encrypt_send_keyid(int dir, const unsigned char *keyid, int keylen, int saveit) { unsigned char *strp; @@ -812,9 +777,8 @@ encrypt_send_keyid(dir, keyid, keylen, s printsub('>', &str_keyid[2], strp - str_keyid - 2); } - void -encrypt_auto(on) - int on; +void +encrypt_auto(int on) { if (on < 0) autoencrypt ^= 1; @@ -822,9 +786,8 @@ encrypt_auto(on) autoencrypt = on ? 1 : 0; } - void -decrypt_auto(on) - int on; +void +decrypt_auto(int on) { if (on < 0) autodecrypt ^= 1; @@ -832,9 +795,8 @@ decrypt_auto(on) autodecrypt = on ? 1 : 0; } - void -encrypt_start_output(type) - int type; +void +encrypt_start_output(int type) { Encryptions *ep; register unsigned char *p; @@ -889,8 +851,8 @@ encrypt_start_output(type) ENCTYPE_NAME(type)); } - void -encrypt_send_end() +void +encrypt_send_end(void) { if (!encrypt_output) return; @@ -910,8 +872,8 @@ encrypt_send_end() printf("[ Output is now clear text ]\r\n"); } - void -encrypt_send_request_start() +void +encrypt_send_request_start(void) { register unsigned char *p; register int i; @@ -930,8 +892,8 @@ encrypt_send_request_start() printf(">>>%s: Request input to be encrypted\r\n", Name); } - void -encrypt_send_request_end() +void +encrypt_send_request_end(void) { str_end[3] = ENCRYPT_REQEND; telnet_net_write(str_end, sizeof(str_end)); @@ -941,8 +903,8 @@ encrypt_send_request_end() printf(">>>%s: Request input to be clear text\r\n", Name); } - void -encrypt_wait() +void +encrypt_wait(void) { if (encrypt_debug_mode) printf(">>>%s: in encrypt_wait\r\n", Name); @@ -953,17 +915,15 @@ encrypt_wait() return; } - void -encrypt_debug(mode) - int mode; +void +encrypt_debug(int mode) { encrypt_debug_mode = mode; } - void -encrypt_gen_printsub(data, cnt, buf, buflen) - unsigned char *data, *buf; - int cnt, buflen; +void +encrypt_gen_printsub(unsigned char *data, int cnt, + unsigned char *buf, int buflen) { char tbuf[16], *cp; @@ -982,10 +942,9 @@ encrypt_gen_printsub(data, cnt, buf, buf *buf = '\0'; } - void -encrypt_printsub(data, cnt, buf, buflen) - unsigned char *data, *buf; - int cnt, buflen; +void +encrypt_printsub(unsigned char *data, int cnt, + unsigned char *buf, int buflen) { Encryptions *ep; register int type = data[1];