Skip to content

Commit

Permalink
Sync from rspamd
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Mar 14, 2016
1 parent 0688254 commit a8ee174
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
8 changes: 0 additions & 8 deletions src/dns_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
#include "upstream.h"
#include "ref.h"

static const unsigned base = 36;
static const unsigned t_min = 1;
static const unsigned t_max = 26;
static const unsigned skew = 38;
static const unsigned damp = 700;
static const unsigned initial_n = 128;
static const unsigned initial_bias = 72;

static const int dns_port = 53;
static const int default_io_cnt = 8;

Expand Down
8 changes: 4 additions & 4 deletions src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void rdns_logger_helper (struct rdns_resolver *resolver,
enum rdns_log_level level,
const char *function, const char *format, ...);

#define rdns_err(...) do { rdns_logger_helper (resolver, RDNS_LOG_ERROR, __FUNCTION__, __VA_ARGS__); } while (0)
#define rdns_warn(...) do { rdns_logger_helper (resolver, RDNS_LOG_WARNING, __FUNCTION__, __VA_ARGS__); } while (0)
#define rdns_info(...) do { rdns_logger_helper (resolver, RDNS_LOG_INFO, __FUNCTION__, __VA_ARGS__); } while (0)
#define rdns_debug(...) do { rdns_logger_helper (resolver, RDNS_LOG_DEBUG, __FUNCTION__, __VA_ARGS__); } while (0)
#define rdns_err(...) do { rdns_logger_helper (resolver, RDNS_LOG_ERROR, __func__, __VA_ARGS__); } while (0)
#define rdns_warn(...) do { rdns_logger_helper (resolver, RDNS_LOG_WARNING, __func__, __VA_ARGS__); } while (0)
#define rdns_info(...) do { rdns_logger_helper (resolver, RDNS_LOG_INFO, __func__, __VA_ARGS__); } while (0)
#define rdns_debug(...) do { rdns_logger_helper (resolver, RDNS_LOG_DEBUG, __func__, __VA_ARGS__); } while (0)

#endif /* LOGGER_H_ */
21 changes: 13 additions & 8 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
}

/* We need to encode */

p = in;
olen = inlen + 1 + sizeof ("xn--") * labels;
*out = malloc (olen);
/* We allocate 4 times more memory as we cannot guarantee encoding bounds */
olen = inlen * sizeof (int32_t) + 1 + sizeof ("xn--") * labels;
*out = malloc (olen + 1);

if (*out == NULL) {
return false;
Expand All @@ -158,8 +158,7 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
}
else {
rdns_info ("no buffer remain for punycoding query");
free (*out);
return false;
goto err;
}

free (uclabel);
Expand All @@ -183,7 +182,7 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
}
if (remain < label_len + 1) {
rdns_info ("no buffer remain for punycoding query");
return false;
goto err;
}
if (label_len == 0) {
/* Two dots in order, skip this */
Expand All @@ -208,7 +207,7 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
}
if (remain < label_len + 1) {
rdns_info ("no buffer remain for punycoding query");
return false;
goto err;
}
memcpy (o, p, label_len);
o += label_len;
Expand All @@ -220,14 +219,20 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
}
if (remain == 0) {
rdns_info ("no buffer remain for punycoding query");
return false;
goto err;
}
}

*o = '\0';

*outlen = o - *out;

return true;

err:
free (*out);
*out = NULL;
return false;
}

bool
Expand Down
8 changes: 7 additions & 1 deletion src/punycode.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
*/

#include "dns_private.h"

static const unsigned base = 36;
static const unsigned t_min = 1;
static const unsigned t_max = 26;
static const unsigned skew = 38;
static const unsigned damp = 700;
static const unsigned initial_n = 128;
static const unsigned initial_bias = 72;
/* Punycode utility */
static unsigned int
digit (unsigned n)
Expand Down

0 comments on commit a8ee174

Please sign in to comment.