Changeset f450ac9 in mod_gnutls for src/gnutls_cache.c


Ignore:
Timestamp:
Jun 9, 2016, 2:50:43 PM (4 years ago)
Author:
Thomas Klute <thomas2.klute@…>
Branches:
debian/master, debian/stretch-backports, master, upstream
Children:
70a1e5a
Parents:
d18afb8
git-author:
Thomas Klute <thomas2.klute@…> (06/09/16 14:36:10)
git-committer:
Thomas Klute <thomas2.klute@…> (06/09/16 14:50:43)
Message:

Replace mgs_session_id2sz() with apr_(p?)escape_hex()

There's no need to carry a local bin-to-hex function if APR already
provides a converter. Using integrated pool allocation even avoids a
few string copies in gnutls_hooks.c.

The session hex buffers in gnutls_cache.c don't need room for the
memcache tag because it is added in a apr_psprintf() call if
necessary, so we can save a few bytes of stack space there.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_cache.c

    rd18afb8 rf450ac9  
    2727
    2828#include "apr_dbm.h"
     29#include <apr_escape.h>
    2930
    3031#include "ap_mpm.h"
     
    4445 */
    4546#define MC_TAG "mod_gnutls:"
    46 #define MC_TAG_LEN sizeof(MC_TAG)
    47 #define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN)
     47/* two characters per byte, plus one more for '\0' */
     48#define GNUTLS_SESSION_ID_STRING_LEN ((GNUTLS_MAX_SESSION_ID_SIZE * 2) + 1)
    4849
    4950#if MODULE_MAGIC_NUMBER_MAJOR < 20081201
     
    5455APLOG_USE_MODULE(gnutls);
    5556#endif
    56 
    57 char *mgs_session_id2sz(unsigned char *id, int idlen,
    58         char *str, int strsize) {
    59     char *cp;
    60     int n;
    61 
    62     cp = str;
    63     for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) {
    64         apr_snprintf(cp, strsize - (cp - str), "%02X", id[n]);
    65         cp += 2;
    66     }
    67     *cp = '\0';
    68     return str;
    69 }
    7057
    7158/* Name the Session ID as:
     
    7663                              gnutls_datum_t *dbmkey)
    7764{
    78     char buf[STR_SESSION_LEN];
    79     char *sz;
    80 
    81     sz = mgs_session_id2sz(id, idlen, buf, sizeof (buf));
    82     if (sz == NULL)
     65    char sz[GNUTLS_SESSION_ID_STRING_LEN];
     66    apr_status_t rv = apr_escape_hex(sz, id, idlen, 0, NULL);
     67    if (rv != APR_SUCCESS)
    8368        return -1;
    8469
     
    11398 * to disallow resuming sessions on different servers
    11499 */
    115 static char *mgs_session_id2mc(conn_rec * c, unsigned char *id, int idlen) {
    116     char buf[STR_SESSION_LEN];
    117     char *sz;
    118 
    119     sz = mgs_session_id2sz(id, idlen, buf, sizeof (buf));
    120     if (sz == NULL)
     100static char *mgs_session_id2mc(conn_rec * c, unsigned char *id, int idlen)
     101{
     102    char sz[GNUTLS_SESSION_ID_STRING_LEN];
     103    apr_status_t rv = apr_escape_hex(sz, id, idlen, 0, NULL);
     104    if (rv != APR_SUCCESS)
    121105        return NULL;
    122106
Note: See TracChangeset for help on using the changeset viewer.