diff --git a/lib/aes.c b/lib/aes.c index 1526dfde..ebe841a1 100644 --- a/lib/aes.c +++ b/lib/aes.c @@ -443,12 +443,12 @@ static void BlockCopy(uint8_t* output, uint8_t* input) void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t* output) { - // Copy input to output, and work in-memory on output - BlockCopy(output, input); - // The array that stores the round keys. uint8_t roundKey[176]; + // Copy input to output, and work in-memory on output + BlockCopy(output, input); + KeyExpansion(key, roundKey); // The next function call encrypts the PlainText with the Key using AES algorithm. @@ -457,12 +457,12 @@ void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t* output) void AES128_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t *output) { - // Copy input to output, and work in-memory on output - BlockCopy(output, input); - // The array that stores the round keys. uint8_t roundKey[176]; + // Copy input to output, and work in-memory on output + BlockCopy(output, input); + // The KeyExpansion routine must be called before encryption. KeyExpansion(key, roundKey); diff --git a/lib/compat.c b/lib/compat.c index f84ec6f2..9531adda 100644 --- a/lib/compat.c +++ b/lib/compat.c @@ -173,7 +173,12 @@ ssize_t writev(int fd, const struct iovec *vector, int count) { /* Find the total number of bytes to be written. */ size_t bytes = 0; - for (int i = 0; i < count; ++i) { + int i; + char *buffer; + size_t to_copy; + char *bp; + + for (i = 0; i < count; ++i) { /* Check for ssize_t overflow. */ if (((ssize_t)-1) - bytes < vector[i].iov_len) { errno = EINVAL; @@ -182,16 +187,16 @@ ssize_t writev(int fd, const struct iovec *vector, int count) bytes += vector[i].iov_len; } - char *buffer = (char *)malloc(bytes); + buffer = (char *)malloc(bytes); if (buffer == NULL) /* XXX I don't know whether it is acceptable to try writing the data in chunks. Probably not so we just fail here. */ return -1; /* Copy the data into BUFFER. */ - size_t to_copy = bytes; - char *bp = buffer; - for (int i = 0; i < count; ++i) { + to_copy = bytes; + bp = buffer; + for (i = 0; i < count; ++i) { size_t copy = (vector[i].iov_len < to_copy) ? vector[i].iov_len : to_copy; memcpy((void *)bp, (void *)vector[i].iov_base, copy); @@ -214,7 +219,12 @@ ssize_t readv (int fd, const struct iovec *vector, int count) { /* Find the total number of bytes to be read. */ size_t bytes = 0; - for (int i = 0; i < count; ++i) + int i; + char *buffer; + ssize_t bytes_read; + char *bp; + + for (i = 0; i < count; ++i) { /* Check for ssize_t overflow. */ if (((ssize_t)-1) - bytes < vector[i].iov_len) { @@ -224,12 +234,12 @@ ssize_t readv (int fd, const struct iovec *vector, int count) bytes += vector[i].iov_len; } - char *buffer = (char *)malloc(bytes); + buffer = (char *)malloc(bytes); if (buffer == NULL) return -1; /* Read the data. */ - ssize_t bytes_read = read(fd, buffer, bytes); + bytes_read = read(fd, buffer, bytes); if (bytes_read < 0) { free(buffer); return -1; @@ -237,8 +247,8 @@ ssize_t readv (int fd, const struct iovec *vector, int count) /* Copy the data from BUFFER into the memory specified by VECTOR. */ bytes = bytes_read; - char *bp = buffer; - for (int i = 0; i < count; ++i) { + bp = buffer; + for (i = 0; i < count; ++i) { size_t copy = (vector[i].iov_len < bytes) ? vector[i].iov_len : bytes; memcpy((void *)vector[i].iov_base, (void *)bp, copy); diff --git a/lib/init.c b/lib/init.c index cb8469b7..1c287810 100644 --- a/lib/init.c +++ b/lib/init.c @@ -183,6 +183,8 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url) struct smb2_url *u; char *ptr, *tmp, str[MAX_URL_SIZE]; char *args; + char *shared_folder; + int len_shared_folder; if (strncmp(url, "smb://", 6)) { smb2_set_error(smb2, "URL does not start with 'smb://'"); @@ -210,12 +212,12 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url) ptr = str; - char *shared_folder = strchr(ptr, '/'); + shared_folder = strchr(ptr, '/'); if (!shared_folder) { smb2_set_error(smb2, "Wrong URL format"); return NULL; } - int len_shared_folder = strlen(shared_folder); + len_shared_folder = strlen(shared_folder); /* domain */ if ((tmp = strchr(ptr, ';')) != NULL && strlen(tmp) > len_shared_folder) { diff --git a/lib/smb2-cmd-set-info.c b/lib/smb2-cmd-set-info.c index c408348c..08c2a5eb 100644 --- a/lib/smb2-cmd-set-info.c +++ b/lib/smb2-cmd-set-info.c @@ -59,6 +59,7 @@ smb2_encode_set_info_request(struct smb2_context *smb2, struct smb2_iovec *iov; struct smb2_file_end_of_file_info *eofi; struct smb2_file_rename_info *rni; + struct utf16 *name; len = SMB2_SET_INFO_REQUEST_SIZE & 0xfffffffe; buf = calloc(len, sizeof(uint8_t)); @@ -112,7 +113,7 @@ smb2_encode_set_info_request(struct smb2_context *smb2, case SMB2_FILE_RENAME_INFORMATION: rni = req->input_data; - struct utf16 *name = utf8_to_utf16((char *)(rni->file_name)); + name = utf8_to_utf16((char *)(rni->file_name)); if (name == NULL) { smb2_set_error(smb2, "Could not convert name into UTF-16"); return -1; diff --git a/lib/socket.c b/lib/socket.c index d7525bec..2ad0b256 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -855,7 +855,11 @@ connect_async_ai(struct smb2_context *smb2, const struct addrinfo *ai, int *fd_o t_socket fd; socklen_t socksize; struct sockaddr_storage ss; - +#if 0 == CONFIGURE_OPTION_TCP_LINGER + int const yes = 1; + struct LingerStruct { int l_onoff; /* linger active */ int l_linger; /* how many seconds to linger for */ }; + struct LingerStruct const lin = { .l_onoff = 1, .l_linger = 0 }; /* if l_linger is zero, sends RST after FIN */ +#endif memset(&ss, 0, sizeof(ss)); switch (ai->ai_family) { case AF_INET: @@ -894,10 +898,7 @@ connect_async_ai(struct smb2_context *smb2, const struct addrinfo *ai, int *fd_o set_tcp_sockopt(fd, TCP_NODELAY, 1); #if 0 == CONFIGURE_OPTION_TCP_LINGER - int const yes = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes); - struct LingerStruct { int l_onoff; /* linger active */ int l_linger; /* how many seconds to linger for */ }; - struct LingerStruct const lin = { .l_onoff = 1, .l_linger = 0 }; /* if l_linger is zero, sends RST after FIN */ setsockopt(fd, SOL_SOCKET, SO_LINGER, &lin, sizeof lin); #endif diff --git a/lib/unicode.c b/lib/unicode.c index 60c0c2a3..bdae493b 100644 --- a/lib/unicode.c +++ b/lib/unicode.c @@ -71,9 +71,9 @@ validate_utf8_cp(const char **utf8, uint16_t *ret) { int c = *(*utf8)++; int l, l_tmp; - l = l_tmp = l1(c); uint32_t cp; - + l = l_tmp = l1(c); + switch (l) { case 0: /* 7-bit ascii is always ok */ @@ -208,12 +208,12 @@ utf16_size(const uint16_t *utf16, int utf16_len) } else if (code < 0xd800 || code - 0xe000 < 0x2000) { length += 3; } else if (code < 0xdc00) { /* Surrogate pair */ - + uint32_t trail; if (utf16 == utf16_end) { /* It's possible the stream ends with a leading code unit, which is an error */ return length + 3; /* Replacement char */ } - uint32_t trail = le16toh(*utf16); + trail = le16toh(*utf16); if (trail - 0xdc00 < 0x400) { /* Check that 0xdc00 <= trail < 0xe000 */ code = 0x10000 + ((code & 0x3ff) << 10) + (trail & 0x3ff); if (code < 0x10000) { @@ -241,7 +241,8 @@ utf16_to_utf8(const uint16_t *utf16, int utf16_len) { int utf8_len = 1; char *str, *tmp; - + const uint16_t *utf16_end; + /* How many bytes do we need for utf8 ? */ utf8_len += utf16_size(utf16, utf16_len); str = tmp = (char*)malloc(utf8_len); @@ -250,7 +251,7 @@ utf16_to_utf8(const uint16_t *utf16, int utf16_len) } str[utf8_len - 1] = 0; - const uint16_t *utf16_end = utf16 + utf16_len; + utf16_end = utf16 + utf16_len; while (utf16 < utf16_end) { uint32_t code = le16toh(*utf16++); @@ -264,13 +265,13 @@ utf16_to_utf8(const uint16_t *utf16, int utf16_len) *tmp++ = 0x80 | ((code >> 6) & 0x3f); *tmp++ = 0x80 | ((code ) & 0x3f); } else if (code < 0xdc00) { /* Surrogate pair */ - + uint32_t trail; if (utf16 == utf16_end) { /* It's possible the stream ends with a leading code unit, which is an error */ *tmp++ = 0xef; *tmp++ = 0xbf; *tmp++ = 0xbd; /* Replacement char */ return str; } - uint32_t trail = le16toh(*utf16); + trail = le16toh(*utf16); if (trail - 0xdc00 < 0x400) { /* Check that 0xdc00 <= trail < 0xe000 */ code = 0x10000 + ((code & 0x3ff) << 10) + (trail & 0x3ff); if (code < 0x10000) {