Skip to content

Commit

Permalink
Lint fix: define some variables in smaller scope
Browse files Browse the repository at this point in the history
  • Loading branch information
droe committed Jan 14, 2014
1 parent cd358e2 commit e1d8a2a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ base64_enc(const unsigned char *in, size_t insz, size_t *outsz)
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/' };
size_t i, o;
int tmp;
char *out;

if (insz == 0) {
Expand All @@ -168,6 +167,7 @@ base64_enc(const unsigned char *in, size_t insz, size_t *outsz)
}

for (i = 0, o = 0; i < insz; i += 3, o += 4) {
int tmp;
tmp = in[i ] << 16;
if (i + 1 < insz)
tmp += in[i + 1] << 8;
Expand Down
2 changes: 1 addition & 1 deletion cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ cache_val_t
cache_get(cache_t *cache, cache_key_t key)
{
cache_val_t rval = NULL;
cache_val_t val;
khiter_t it;

if (!key)
Expand All @@ -117,6 +116,7 @@ cache_get(cache_t *cache, cache_key_t key)
pthread_mutex_lock(&cache->mutex);
it = cache->get_cb(key);
if (it != cache->end_cb()) {
cache_val_t val;
val = cache->get_val_cb(it);
if (!(rval = cache->unpackverify_val_cb(val, 1))) {
cache->free_val_cb(val);
Expand Down
10 changes: 5 additions & 5 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ log_content_close_singlefile(void)
void
log_content_open(log_content_ctx_t *ctx, char *srcaddr, char *dstaddr)
{
char filename[1024];
char timebuf[24];
time_t epoch;
struct tm *utc;

if (ctx->open)
return;

Expand All @@ -264,6 +259,11 @@ log_content_open(log_content_ctx_t *ctx, char *srcaddr, char *dstaddr)
asprintf(&ctx->header_in, "%s -> %s", srcaddr, dstaddr);
asprintf(&ctx->header_out, "%s -> %s", dstaddr, srcaddr);
} else {
char filename[1024];
char timebuf[24];
time_t epoch;
struct tm *utc;

time(&epoch);
utc = gmtime(&epoch);
strftime(timebuf, sizeof(timebuf), "%Y%m%dT%H%M%SZ", utc);
Expand Down
2 changes: 1 addition & 1 deletion logbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ logbuf_size(logbuf_t *lb)
ssize_t
logbuf_write_free(logbuf_t *lb, writefunc_t writefunc)
{
ssize_t rv1, rv2;
ssize_t rv1, rv2 = 0;

rv1 = writefunc(lb->fd, lb->buf, lb->sz);
free(lb->buf);
Expand Down
28 changes: 18 additions & 10 deletions pxyconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ static cert_t *
pxy_srccert_create(pxy_conn_ctx_t *ctx)
{
cert_t *cert = NULL;
char *wildcarded;

if (ctx->opts->tgcrtdir) {
if (ctx->sni) {
cert = cachemgr_tgcrt_get(ctx->sni);
if (!cert) {
char *wildcarded;
wildcarded = ssl_wildcardify(ctx->sni);
if (!wildcarded) {
ctx->enomem = 1;
Expand All @@ -588,6 +588,7 @@ pxy_srccert_create(pxy_conn_ctx_t *ctx)
cert = cachemgr_tgcrt_get(*p);
}
if (!cert) {
char *wildcarded;
wildcarded = ssl_wildcardify(*p);
if (!wildcarded) {
ctx->enomem = 1;
Expand Down Expand Up @@ -717,7 +718,7 @@ pxy_ossl_servername_cb(SSL *ssl, UNUSED int *al, void *arg)
{
pxy_conn_ctx_t *ctx = arg;
const char *sn;
X509 *sslcrt, *newcrt;
X509 *sslcrt;

if (!(sn = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name)))
return SSL_TLSEXT_ERR_NOACK;
Expand All @@ -744,6 +745,9 @@ pxy_ossl_servername_cb(SSL *ssl, UNUSED int *al, void *arg)
* and replace it both in the current SSL ctx and in the cert cache */
if (!ctx->immutable_cert &&
!ssl_x509_names_match((sslcrt = SSL_get_certificate(ssl)), sn)) {
X509 *newcrt;
SSL_CTX *newsslctx;

if (OPTS_DEBUG(ctx->opts)) {
log_dbg_printf("Certificate cache: UPDATE "
"(SNI mismatch)\n");
Expand All @@ -769,7 +773,6 @@ pxy_ossl_servername_cb(SSL *ssl, UNUSED int *al, void *arg)
ctx->enomem = 1;
}
}
SSL_CTX *newsslctx;
newsslctx = pxy_srcsslctx_create(ctx, newcrt, ctx->opts->chain,
ctx->opts->key);
if (!newsslctx) {
Expand Down Expand Up @@ -947,11 +950,11 @@ pxy_bufferevent_setup(pxy_conn_ctx_t *ctx, evutil_socket_t fd, SSL *ssl)
static char *
pxy_http_reqhdr_filter_line(const char *line, pxy_conn_ctx_t *ctx)
{
char *space1, *space2, *newhdr;

/* parse information for connect log */
if (!ctx->http_method) {
/* first line */
char *space1, *space2;

space1 = strchr(line, ' ');
space2 = space1 ? strchr(space1 + 1, ' ') : NULL;
if (!space1) {
Expand Down Expand Up @@ -983,6 +986,8 @@ pxy_http_reqhdr_filter_line(const char *line, pxy_conn_ctx_t *ctx)
}
} else {
/* not first line */
char *newhdr;

if (!ctx->http_host && !strncasecmp(line, "Host: ", 6)) {
ctx->http_host = strdup(util_skipws(line + 6));
if (!ctx->http_host) {
Expand Down Expand Up @@ -1031,18 +1036,19 @@ pxy_http_reqhdr_filter_line(const char *line, pxy_conn_ctx_t *ctx)
static char *
pxy_http_resphdr_filter_line(const char *line, pxy_conn_ctx_t *ctx)
{
char *space1, *space2;
size_t len_code, len_text;

/* parse information for connect log */
if (!ctx->http_status_code) {
/* first line */
char *space1, *space2;

space1 = strchr(line, ' ');
space2 = space1 ? strchr(space1 + 1, ' ') : NULL;
if (!space1 || !!strncmp(line, "HTTP", 4)) {
/* not HTTP or HTTP/0.9 */
ctx->seen_resp_header = 1;
} else {
size_t len_code, len_text;

if (space2) {
len_code = space2 - space1 - 1;
len_text = strlen(space2 + 1);
Expand Down Expand Up @@ -1251,9 +1257,10 @@ pxy_bev_readcb(struct bufferevent *bev, void *arg)
if (ctx->spec->http && !ctx->seen_req_header && (bev == ctx->src.bev)
&& !ctx->passthrough) {
logbuf_t *lb = NULL, *tail = NULL;
char *line, *replace;
char *line;
while ((line = evbuffer_readln(inbuf, NULL,
EVBUFFER_EOL_CRLF))) {
char *replace;
if (WANT_CONTENT_LOG(ctx)) {
logbuf_t *tmp;
tmp = logbuf_new_printf(-1, NULL,
Expand Down Expand Up @@ -1293,9 +1300,10 @@ pxy_bev_readcb(struct bufferevent *bev, void *arg)
if (ctx->spec->http && !ctx->seen_resp_header && (bev == ctx->dst.bev)
&& !ctx->passthrough) {
logbuf_t *lb = NULL, *tail = NULL;
char *line, *replace;
char *line;
while ((line = evbuffer_readln(inbuf, NULL,
EVBUFFER_EOL_CRLF))) {
char *replace;
if (WANT_CONTENT_LOG(ctx)) {
logbuf_t *tmp;
tmp = logbuf_new_printf(-1, NULL,
Expand Down
12 changes: 6 additions & 6 deletions ssl.t.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ END_TEST

START_TEST(ssl_tls_clienthello_parse_sni_05)
{
ssize_t sz;
char *sni;

for (size_t i = 0; i < sizeof(clienthello04) - 1; i++) {
ssize_t sz;
char *sni;

sz = (ssize_t)i;
sni = ssl_tls_clienthello_parse_sni(clienthello04, &sz);
fail_unless(sni == NULL, "sni not null but should be");
Expand All @@ -391,10 +391,10 @@ END_TEST

START_TEST(ssl_tls_clienthello_parse_sni_07)
{
ssize_t sz;
char *sni;

for (size_t i = 0; i < sizeof(clienthello05) - 1; i++) {
ssize_t sz;
char *sni;

sz = (ssize_t)i;
sni = ssl_tls_clienthello_parse_sni(clienthello05, &sz);
fail_unless(sni == NULL, "sni not null but should be");
Expand Down

0 comments on commit e1d8a2a

Please sign in to comment.