1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-18 15:20:56 +03:00

src: add and use LIBSSH2_MIN/MAX macros

Also for #797

Closes #974
This commit is contained in:
Viktor Szakats
2023-04-16 15:48:59 +00:00
parent 78cb64a859
commit 9ffbb05b44
4 changed files with 11 additions and 12 deletions

View File

@@ -28,8 +28,6 @@
#define LIBSSH2_BCRYPT_PBKDF_C #define LIBSSH2_BCRYPT_PBKDF_C
#include "blowfish.c" #include "blowfish.c"
#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
/* /*
* pkcs #5 pbkdf2 implementation using the "bcrypt" hash * pkcs #5 pbkdf2 implementation using the "bcrypt" hash
* *
@@ -164,7 +162,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
/* /*
* pbkdf2 deviation: output the key material non-linearly. * pbkdf2 deviation: output the key material non-linearly.
*/ */
amt = MINIMUM(amt, keylen); amt = LIBSSH2_MIN(amt, keylen);
for(i = 0; i < amt; i++) { for(i = 0; i < amt; i++) {
size_t dest = i * stride + (count - 1); size_t dest = i * stride + (count - 1);
if(dest >= origkeylen) { if(dest >= origkeylen) {

View File

@@ -156,6 +156,9 @@ struct iovec {
#define UINT_MAX 0xFFFFFFFF #define UINT_MAX 0xFFFFFFFF
#endif #endif
#define LIBSSH2_MAX(x, y) ((x) > (y) ? (x) : (y))
#define LIBSSH2_MIN(x, y) ((x) < (y) ? (x) : (y))
/* RFC4253 section 6.1 Maximum Packet Length says: /* RFC4253 section 6.1 Maximum Packet Length says:
* *
* "All implementations MUST be able to process packets with * "All implementations MUST be able to process packets with

View File

@@ -1405,7 +1405,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return that now as we can't risk being interrupted later with data return that now as we can't risk being interrupted later with data
partially written to the buffer. */ partially written to the buffer. */
if(filep->data_left) { if(filep->data_left) {
size_t copy = MIN(buffer_size, filep->data_left); size_t copy = LIBSSH2_MIN(buffer_size, filep->data_left);
memcpy(buffer, &filep->data[ filep->data_len - filep->data_left], memcpy(buffer, &filep->data[ filep->data_len - filep->data_left],
copy); copy);
@@ -1519,8 +1519,9 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* add this new entry LAST in the list */ /* add this new entry LAST in the list */
_libssh2_list_add(&handle->packet_list, &chunk->node); _libssh2_list_add(&handle->packet_list, &chunk->node);
count -= MIN(size, count); /* deduct the size we used, as we might /* deduct the size we used, as we might have to create
* have to create more packets */ more packets */
count -= LIBSSH2_MIN(size, count);
_libssh2_debug((session, LIBSSH2_TRACE_SFTP, _libssh2_debug((session, LIBSSH2_TRACE_SFTP,
"read request id %d sent (offset: %d, size: %d)", "read request id %d sent (offset: %d, size: %d)",
request_id, (int)chunk->offset, (int)chunk->len)); request_id, (int)chunk->offset, (int)chunk->len));
@@ -2076,7 +2077,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
while(count) { while(count) {
/* TODO: Possibly this should have some logic to prevent a very /* TODO: Possibly this should have some logic to prevent a very
very small fraction to be left but lets ignore that for now */ very small fraction to be left but lets ignore that for now */
uint32_t size = (uint32_t)(MIN(MAX_SFTP_OUTGOING_SIZE, count)); uint32_t size =
(uint32_t)(LIBSSH2_MIN(MAX_SFTP_OUTGOING_SIZE, count));
uint32_t request_id; uint32_t request_id;
/* 25 = packet_len(4) + packet_type(1) + request_id(4) + /* 25 = packet_len(4) + packet_type(1) + request_id(4) +
@@ -2226,7 +2228,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
acked += handle->u.file.acked; acked += handle->u.file.acked;
if(acked) { if(acked) {
ssize_t ret = MIN(acked, org_count); ssize_t ret = LIBSSH2_MIN(acked, org_count);
/* we got data acked so return that amount, but no more than what /* we got data acked so return that amount, but no more than what
was asked to get sent! */ was asked to get sent! */

View File

@@ -67,10 +67,6 @@ struct sftp_zombie_requests {
uint32_t request_id; uint32_t request_id;
}; };
#ifndef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#endif
struct _LIBSSH2_SFTP_PACKET struct _LIBSSH2_SFTP_PACKET
{ {
struct list_node node; /* linked list header */ struct list_node node; /* linked list header */