1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
$NetBSD: patch-af,v 1.1 2005/09/19 19:42:11 adrianp Exp $
--- libgadu-0.1/common.c.orig 2004-07-31 11:47:20.000000000 +0100
+++ libgadu-0.1/common.c
@@ -284,6 +284,8 @@ char *gg_read_line(int sock, char *buf,
{
int ret;
+ if (!buf || length < 0)
+ return NULL;
for (; length > 1; buf++, length--) {
do {
if ((ret = read(sock, buf, 1)) == -1 && errno != EINTR) {
@@ -340,7 +342,7 @@ char *gg_urlencode(const char *str)
{
char *q, *buf, hex[] = "0123456789abcdef";
const char *p;
- int size = 0;
+ unsigned int size = 0;
if (!str && !(str = strdup("")))
return NULL;
@@ -392,18 +394,18 @@ int gg_http_hash(const char *format, ...
va_start(ap, format);
for (j = 0; j < strlen(format); j++) {
- unsigned char *arg, buf[16];
+ char *arg, buf[16];
if (format[j] == 'u') {
snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t));
arg = buf;
} else {
- if (!(arg = va_arg(ap, unsigned char*)))
+ if (!(arg = va_arg(ap, char*)))
arg = "";
}
i = 0;
- while ((c = (int) arg[i++]) != 0) {
+ while ((c = (unsigned char) arg[i++]) != 0) {
a = (c ^ b) + (c << 8);
b = (a >> 24) | (a << 8);
}
@@ -532,7 +534,7 @@ static char gg_base64_charset[] =
char *gg_base64_encode(const char *buf)
{
char *out, *res;
- int i = 0, j = 0, k = 0, len = strlen(buf);
+ unsigned int i = 0, j = 0, k = 0, len = strlen(buf);
res = out = malloc((len / 3 + 1) * 4 + 2);
@@ -590,7 +592,7 @@ char *gg_base64_decode(const char *buf)
{
char *res, *save, *foo, val;
const char *end;
- int index = 0;
+ unsigned int index = 0;
if (!buf)
return NULL;
@@ -684,7 +686,7 @@ static int gg_crc32_initialized = 0;
static void gg_crc32_make_table()
{
uint32_t h = 0;
- int i, j;
+ unsigned int i, j;
memset(gg_crc32_table, 0, sizeof(gg_crc32_table));
@@ -713,6 +715,8 @@ uint32_t gg_crc32(uint32_t crc, const un
{
if (!gg_crc32_initialized)
gg_crc32_make_table();
+ if (!buf || len < 0)
+ return crc;
crc ^= 0xffffffffL;
|