]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Applied patch by Arne that fixes several possible NULL pointer dereferences.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 3 Oct 2003 09:09:00 +0000 (09:09 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 3 Oct 2003 09:09:00 +0000 (09:09 +0000)
includes/gnutls/Makefile.am
lib/gnutls_alert.c
lib/gnutls_algorithms.c
lib/x509/Makefile.am
lib/x509/rfc2818_hostname.c
libextra/Makefile.am
src/cli.c
src/common.c
src/common.h
src/serv.c

index d7914a5e2ff699650a6dd9173f1e696228d97c46..647b2bdff754fce775d7e7415609d55d2ecdadda 100644 (file)
@@ -1 +1 @@
-EXTRA_DIST = extra.h openssl.h gnutls.h compat4.h x509.h compat8.h pkcs12.h
+EXTRA_DIST = extra.h openssl.h gnutls.h compat4.h x509.h compat8.h pkcs12.h openpgp.h
index 5350650ead5cd5cfbb17f93995093cbf68eedee7..8476f5b5aec5d48c7f07350d75f6cb4173241942 100644 (file)
@@ -108,11 +108,14 @@ int gnutls_alert_send( gnutls_session session, gnutls_alert_level level, gnutls_
 {
        uint8 data[2];
        int ret;
-       
+       const char *name;
+
        data[0] = (uint8) level;
        data[1] = (uint8) desc;
 
-       _gnutls_record_log( "REC: Sending Alert[%d|%d] - %s\n", data[0], data[1], gnutls_alert_get_name((int)data[1]));
+       name = gnutls_alert_get_name((int)data[1]);
+       if (name == NULL) name = "(unknown)";
+       _gnutls_record_log( "REC: Sending Alert[%d|%d] - %s\n", data[0], data[1], name);
 
        if ( (ret = _gnutls_send_int( session, GNUTLS_ALERT, -1, data, 2)) >= 0)
                return 0;
index 796922ab087bf232d9ac7667668ed1f755ea4fd6..e7759385d694339c384802e2e20c059133c5fe51 100644 (file)
@@ -495,8 +495,8 @@ inline int _gnutls_mac_priority(gnutls_session session, gnutls_mac_algorithm alg
   * gnutls_mac_get_name - Returns a string with the name of the specified mac algorithm
   * @algorithm: is a MAC algorithm
   *
-  * Returns a string that contains the name 
-  * of the specified MAC algorithm.
+  * Returns a string that contains the name
+  * of the specified MAC algorithm or NULL.
   **/
 const char *gnutls_mac_get_name( gnutls_mac_algorithm algorithm)
 {
@@ -542,8 +542,8 @@ inline
   * gnutls_compression_get_name - Returns a string with the name of the specified compression algorithm
   * @algorithm: is a Compression algorithm
   *
-  * Returns a pointer to a string that contains the name 
-  * of the specified compression algorithm.
+  * Returns a pointer to a string that contains the name
+  * of the specified compression algorithm or NULL.
   **/
 const char *gnutls_compression_get_name( gnutls_compression_method algorithm)
 {
@@ -691,8 +691,8 @@ int _gnutls_cipher_get_export_flag(gnutls_cipher_algorithm algorithm)
   * gnutls_cipher_get_name - Returns a string with the name of the specified cipher algorithm
   * @algorithm: is an encryption algorithm
   *
-  * Returns a pointer to a string that contains the name 
-  * of the specified cipher.
+  * Returns a pointer to a string that contains the name
+  * of the specified cipher or NULL.
   **/
 const char *gnutls_cipher_get_name( gnutls_cipher_algorithm algorithm)
 {
@@ -744,7 +744,7 @@ inline int _gnutls_kx_priority(gnutls_session session, gnutls_kx_algorithm algor
   * @algorithm: is a key exchange algorithm
   *
   * Returns a pointer to a string that contains the name 
-  * of the specified key exchange algorithm.
+  * of the specified key exchange algorithm or NULL.
   **/
 const char *gnutls_kx_get_name( gnutls_kx_algorithm algorithm)
 {
@@ -829,8 +829,8 @@ gnutls_protocol_version _gnutls_version_max(gnutls_session session)
   * gnutls_protocol_get_name - Returns a string with the name of the specified SSL/TLS version
   * @version: is a (gnutls) version number
   *
-  * Returns a string that contains the name 
-  * of the specified TLS version.
+  * Returns a string that contains the name
+  * of the specified TLS version or NULL.
   **/
 const char *gnutls_protocol_get_name( gnutls_protocol_version version)
 {
@@ -965,7 +965,7 @@ const char *_gnutls_cipher_suite_get_name(GNUTLS_CipherSuite suite)
   * @mac_algorithm: is a MAC algorithm
   *
   * Returns a string that contains the name of a TLS
-  * cipher suite, specified by the given algorithms.
+  * cipher suite, specified by the given algorithms, or NULL.
   *
   * Note that the full cipher suite name must be prepended
   * by TLS or SSL depending of the protocol in use.
index abc53f3c1b4335104fd5718cf40165aa23977750..013fe9787713a2c6b182f133f6552cc048d5bde8 100644 (file)
@@ -1,7 +1,7 @@
 INCLUDES = -I../ -I../minitasn1/ -I../../includes/
 EXTRA_DIST = dn.h common.h x509.h extensions.h pkcs7.h \
        x509-api.tex compat.h verify.h mpi.h crq.h sign.h pkcs5.h \
-       privkey.h pkcs12.h rc2.h
+       privkey.h pkcs12.h rc2.h rfc2818.h
 
 noinst_LTLIBRARIES = libx509.la
 #lib_LTLIBRARIES = libgnutls-x509.la
index 6a903b0173e62460bef07597e4198e06bf0713ea..d83ede108378f153472f2816d4cdb1f37a07712a 100644 (file)
@@ -26,8 +26,7 @@
 #include <dn.h>
 #include <common.h>
 #include <gnutls/compat8.h>
-
-static int hostname_compare(const char *certname, const char *hostname);
+#include <rfc2818.h>
 
 /*-
   * gnutls_x509_check_certificates_hostname - This function compares the given hostname with the hostname in the certificate
@@ -44,7 +43,6 @@ static int hostname_compare(const char *certname, const char *hostname);
 int gnutls_x509_check_certificates_hostname(const gnutls_datum * cert,
                                 const char *hostname)
 {
-#define MAX_CN 256
    char dnsname[MAX_CN];
    int dnsnamesize;
    int found_dnsname = 0;
@@ -76,7 +74,7 @@ int gnutls_x509_check_certificates_hostname(const gnutls_datum * cert,
 
       if (ret == GNUTLS_SAN_DNSNAME) {
          found_dnsname = 1;
-         if (hostname_compare(dnsname, hostname)) {
+         if (_gnutls_hostname_compare(dnsname, hostname)) {
             return 1;
          }
       }
@@ -92,7 +90,7 @@ int gnutls_x509_check_certificates_hostname(const gnutls_datum * cert,
          return 0;
       }
 
-      if (hostname_compare(dn.common_name, hostname)) {
+      if (_gnutls_hostname_compare(dn.common_name, hostname)) {
          return 1;
       }
    }
@@ -105,7 +103,7 @@ int gnutls_x509_check_certificates_hostname(const gnutls_datum * cert,
 /* compare hostname against certificate, taking account of wildcards
  * return 1 on success or 0 on error 
  */
-static int hostname_compare(const char *certname, const char *hostname)
+int _gnutls_hostname_compare(const char *certname, const char *hostname)
 {
    const char *cmpstr1, *cmpstr2;
 
@@ -184,7 +182,7 @@ int gnutls_x509_crt_check_hostname(gnutls_x509_crt cert,
 
       if (ret == GNUTLS_SAN_DNSNAME) {
          found_dnsname = 1;
-         if (hostname_compare(dnsname, hostname)) {
+         if (_gnutls_hostname_compare(dnsname, hostname)) {
             return 1;
          }
       }
@@ -202,7 +200,7 @@ int gnutls_x509_crt_check_hostname(gnutls_x509_crt cert,
          return 0;
       }
 
-      if (hostname_compare(dnsname, hostname)) {
+      if (_gnutls_hostname_compare(dnsname, hostname)) {
          return 1;
       }
    }
index 50f132acf829e264add3f9d5a7375c0a73bc2990..c0999fd79ac4dffbab18a09c01d7f52d110f9525 100644 (file)
@@ -28,12 +28,12 @@ COBJECTS_EXTRA = ext_srp.c \
 libgnutls_extra_la_LDFLAGS = $(libgnutls_extra_version_script_cmd) \
        -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
        $(LIBOPENCDK_LIBS) $(LZO_LINK)
-libgnutls_extra_la_LIBADD = $(LZO_OBJECTS) ../lib/libgnutls.la
 libgnutls_extra_la_DEPENDENCIES = $(LZO_OBJECTS)
 
 libgnutls_extra_la_SOURCES = $(COBJECTS_EXTRA) 
 
-libgnutls_extra_la_LIBADD = openpgp/openpgp.lo openpgp/xml.lo openpgp/gnutls_openpgp.lo
+libgnutls_extra_la_LIBADD = $(LZO_OBJECTS) ../lib/libgnutls.la \
+       openpgp/openpgp.lo openpgp/xml.lo openpgp/gnutls_openpgp.lo
 
 EXTRA_libgnutls_extra_la_SOURCES = minilzo.c
 
index 1189e5e02c83bea633b3fdf9df643596ec70aad6..c5b823a3e92b43e98b324457bd5f9fcefaab17d9 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -35,7 +35,7 @@
 #include <sys/time.h>
 #include <signal.h>
 #include <netdb.h>
-#include <common.h>
+#include "common.h"
 #include "cli-gaa.h"
 
 #ifndef SHUT_WR
@@ -222,7 +222,7 @@ static int handle_error(socket_st hd, int err)
        }
 
        str = gnutls_strerror(err);
-       if (str == NULL) str = "(unknown)";
+       if (str == NULL) str = str_unknown;
        fprintf(stderr,
                "*** %s error: %s\n", err_type, str);
 
@@ -230,7 +230,7 @@ static int handle_error(socket_st hd, int err)
            || err == GNUTLS_E_FATAL_ALERT_RECEIVED) {
                alert = gnutls_alert_get(hd.session);
                str = gnutls_alert_get_name(alert);
-               if (str == NULL) str = "(unknown)";
+               if (str == NULL) str = str_unknown;
                printf("*** Received alert [%d]: %s\n", alert, str);
 
        }
@@ -240,7 +240,7 @@ static int handle_error(socket_st hd, int err)
        return ret;
 }
 
-int starttls_alarmed;
+int starttls_alarmed = 0;
 
 void starttls_alarm (int signum)
 {
index 4fbd6132a820f520d78e7d5d5c1aa8afd1bfd6d5..702136bd2a7f395d170ef21374ea2d4794554788 100644 (file)
@@ -15,6 +15,8 @@ int xml = 0;
 #define PRINT_PGP_NAME(X) PRINTX( "NAME:", X.name); \
        PRINTX( "EMAIL:", X.email)
 
+const char str_unknown[] = "(unknown)";
+
 static const char *my_ctime(const time_t * tv)
 {
        static char buf[256];
@@ -22,7 +24,7 @@ static const char *my_ctime(const time_t * tv)
 
        if ( ( (tp = localtime(tv)) == NULL ) ||
             (!strftime(buf, sizeof buf, "%a %b %e %H:%M:%S %Z %Y\n", tp)) )
-               strcpy(buf, "unknown"); /* make sure buf text isn't garbage */
+               strcpy(buf, str_unknown);/* make sure buf text isn't garbage */
 
        return buf;
 
@@ -64,7 +66,7 @@ void print_x509_info(gnutls_session session, const char* hostname)
                                           GNUTLS_X509_FMT_DER);
                if (ret < 0) {
                        const char* str = gnutls_strerror(ret);
-                       if (str == NULL) str = "(unknown)";
+                       if (str == NULL) str = str_unknown;
                        fprintf(stderr, "Decoding error: %s\n", str);
                        return;
                }
@@ -90,7 +92,7 @@ void print_x509_info(gnutls_session session, const char* hostname)
                        ret = gnutls_x509_crt_to_xml( crt, &xml_data, 0);
                        if (ret < 0) {
                                const char* str = gnutls_strerror(ret);
-                               if (str == NULL) str = "(unknown)";
+                               if (str == NULL) str = str_unknown;
                                fprintf(stderr, "XML encoding error: %s\n",
                                        str);
                                return;
@@ -127,7 +129,7 @@ void print_x509_info(gnutls_session session, const char* hostname)
                        if ((ret=gnutls_x509_crt_get_fingerprint(crt, GNUTLS_DIG_MD5, digest, &digest_size))
                            < 0) {
                                const char* str = gnutls_strerror(ret);
-                               if (str == NULL) str = "(unknown)";
+                               if (str == NULL) str = str_unknown;
                                fprintf(stderr, "Error in fingerprint calculation: %s\n", str);
                        } else {
                                print = printable;
@@ -354,19 +356,19 @@ int print_info(gnutls_session session, const char* hostname)
 
        tmp =
            gnutls_protocol_get_name(gnutls_protocol_get_version(session));
-       printf("- Version: %s\n", tmp);
+       if (tmp != NULL) printf("- Version: %s\n", tmp);
 
        tmp = gnutls_kx_get_name(kx);
-       printf("- Key Exchange: %s\n", tmp);
+       if (tmp != NULL) printf("- Key Exchange: %s\n", tmp);
 
        tmp = gnutls_cipher_get_name(gnutls_cipher_get(session));
-       printf("- Cipher: %s\n", tmp);
+       if (tmp != NULL) printf("- Cipher: %s\n", tmp);
 
        tmp = gnutls_mac_get_name(gnutls_mac_get(session));
-       printf("- MAC: %s\n", tmp);
+       if (tmp != NULL) printf("- MAC: %s\n", tmp);
 
        tmp = gnutls_compression_get_name(gnutls_compression_get(session));
-       printf("- Compression: %s\n", tmp);
+       if (tmp != NULL) printf("- Compression: %s\n", tmp);
 
        fflush (stdout);
 
index 594b33ea9e46f1fa613863edcd579b0c4842edd3..7def7bde997c0740cfad0ddd8fac46132b7058c6 100644 (file)
@@ -7,6 +7,8 @@
  */
 #define PRI_MAX 16
 
+extern const char str_unknown[];
+
 int print_info( gnutls_session state, const char* hostname);
 void print_cert_info( gnutls_session state, const char* hostname);
 void print_list(void);
index 74a3a2bb5929ce4cbcbeba5b39e8dd759613376a..0ffebc8f4adcb73cc302150c43f65fd92faf1c57 100644 (file)
@@ -87,7 +87,7 @@ char *x509_crlfile = NULL;
 
 #define SA struct sockaddr
 #define ERR(err,s) if(err==-1) {perror(s);return(1);}
-#define GERR(ret) fprintf(stdout, "Error: %s\n", gnutls_strerror(ret))
+#define GERR(ret) fprintf(stdout, "Error: %s\n", safe_strerror(ret))
 #define MAX_BUF 1024
 
 #undef max
@@ -134,6 +134,12 @@ LIST_TYPE_DECLARE(listener_item, char *http_request;
                  int http_state;
                  int fd; gnutls_session tls_session; int handshake_ok;);
 
+static const char *safe_strerror(int value)
+{ const char *ret = gnutls_strerror(value);
+  if (ret == NULL) ret = str_unknown;
+  return ret;
+}
+
 static void listener_free(listener_item * j)
 {
    if (j->http_request)
@@ -213,7 +219,7 @@ static void read_dh_params(void)
    size = gnutls_dh_params_import_pkcs3( dh_params, &params, GNUTLS_X509_FMT_PEM);
 
    if (size < 0) {
-       fprintf(stderr, "Error parsing dh params: %s\n", gnutls_strerror(size));
+       fprintf(stderr, "Error parsing dh params: %s\n", safe_strerror(size));
        exit(1);
    }
 
@@ -385,6 +391,7 @@ char *peer_print_info(gnutls_session session, int *ret_length,
    strcat(http_buffer, "<P>\n");
 
    tmp = gnutls_protocol_get_name(gnutls_protocol_get_version(session));
+   if (tmp == NULL) tmp = str_unknown;
    sprintf(tmp2,
           "<TABLE border=1><TR><TD>Protocol version:</TD><TD>%s</TD></TR>\n",
           tmp);
@@ -393,25 +400,31 @@ char *peer_print_info(gnutls_session session, int *ret_length,
       tmp =
          gnutls_certificate_type_get_name(gnutls_certificate_type_get
                                           (session));
+      if (tmp == NULL) tmp = str_unknown;
       sprintf(tmp2, "<TR><TD>Certificate Type:</TD><TD>%s</TD></TR>\n",
              tmp);
    }
 
    tmp = gnutls_kx_get_name(kx_alg);
+   if (tmp == NULL) tmp = str_unknown;
    sprintf(tmp2, "<TR><TD>Key Exchange:</TD><TD>%s</TD></TR>\n", tmp);
 
    tmp = gnutls_compression_get_name(gnutls_compression_get(session));
+   if (tmp == NULL) tmp = str_unknown;
    sprintf(tmp2, "<TR><TD>Compression</TD><TD>%s</TD></TR>\n", tmp);
 
    tmp = gnutls_cipher_get_name(gnutls_cipher_get(session));
+   if (tmp == NULL) tmp = str_unknown;
    sprintf(tmp2, "<TR><TD>Cipher</TD><TD>%s</TD></TR>\n", tmp);
 
    tmp = gnutls_mac_get_name(gnutls_mac_get(session));
+   if (tmp == NULL) tmp = str_unknown;
    sprintf(tmp2, "<TR><TD>MAC</TD><TD>%s</TD></TR>\n", tmp);
 
    tmp = gnutls_cipher_suite_get_name(kx_alg,
                                      gnutls_cipher_get(session),
                                      gnutls_mac_get(session));
+   if (tmp == NULL) tmp = str_unknown;
    sprintf(tmp2, "<TR><TD>Ciphersuite</TD><TD>%s</TD></TR></p></TABLE>\n",
           tmp);
 
@@ -537,8 +550,8 @@ int main(int argc, char **argv)
    signal(SIGPIPE, SIG_IGN);
    signal(SIGHUP, SIG_IGN);
    signal(SIGTERM, terminate);
-   signal(SIGINT, terminate);
-   /* CHECKME: background processes shouldn't handle SIGINT! */
+   if (signal(SIGINT, terminate) == SIG_IGN)
+      signal(SIGINT, SIG_IGN); /* e.g. background process */
 
    gaa_parser(argc, argv);
 
@@ -1108,7 +1121,7 @@ recv_openpgp_key(gnutls_session session, const unsigned char *keyfpr,
                 unsigned int keyfpr_length, gnutls_datum * key)
 {
    static const char hostname[] = "hkp://wwwkeys.pgp.net";
-   static const short port = 11371;
+   static const int port = 11371;
    int rc;
    CDK_KBNODE knode = NULL;
    unsigned int i;