From: Guy Harris Date: Thu, 22 Jul 2021 08:15:31 +0000 (-0700) Subject: Clean up the arguments to sock_bufferize(). X-Git-Tag: libpcap-1.10.2~366 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/f5f0bfcd2bde077857185e250f0693f8cdc7a112 Clean up the arguments to sock_bufferize(). Make the first argument a void * - it can point to anything, not just, for example, a character string. It's not a "buffer", it's just data, whatever that might be, so call it "data", not "buffer". Rename "tempbuf" to "outbuf" to indicate that it's a buffer location into which data is copied. In English, stuff would be contained in "data", not contained into "data" - into suggests that stuff is being copied into it by the routine, which isn't the case - and stuff isn't copied in "outbuf", it's copied into "outbuf". Update the comment for sock_bufferize() to reflect all this. (cherry picked from commit 316cc596afbabbfd97d10473eb6c1eb72f2c5a73) --- diff --git a/sockutils.c b/sockutils.c index ca16bbf2..d9762dd5 100644 --- a/sockutils.c +++ b/sockutils.c @@ -882,11 +882,11 @@ int sock_send(SOCKET sock, SSL *ssl _U_NOSSL_, const char *buffer, size_t size, } /* - * \brief It copies the amount of data contained into 'buffer' into 'tempbuf'. + * \brief It copies the amount of data contained in 'data' into 'outbuf'. * and it checks for buffer overflows. * - * This function basically copies 'size' bytes of data contained into 'buffer' - * into 'tempbuf', starting at offset 'offset'. Before that, it checks that the + * This function basically copies 'size' bytes of data contained in 'data' + * into 'outbuf', starting at offset 'offset'. Before that, it checks that the * resulting buffer will not be larger than 'totsize'. Finally, it updates * the 'offset' variable in order to point to the first empty location of the buffer. * @@ -895,25 +895,24 @@ int sock_send(SOCKET sock, SSL *ssl _U_NOSSL_, const char *buffer, size_t size, * 'offset' variable. This mode can be useful when the buffer already contains the * data (maybe because the producer writes directly into the target buffer), so * only the buffer overflow check has to be made. - * In this case, both 'buffer' and 'tempbuf' can be NULL values. + * In this case, both 'data' and 'outbuf' can be NULL values. * * This function is useful in case the userland application does not know immediately * all the data it has to write into the socket. This function provides a way to create * the "stream" step by step, appending the new data to the old one. Then, when all the * data has been bufferized, the application can call the sock_send() function. * - * \param buffer: a char pointer to a user-allocated buffer that keeps the data - * that has to be copied. + * \param data: a void pointer to the data that has to be copied. * * \param size: number of bytes that have to be copied. * - * \param tempbuf: user-allocated buffer (of size 'totsize') in which data + * \param outbuf: user-allocated buffer (of size 'totsize') into which data * has to be copied. * - * \param offset: an index into 'tempbuf' which keeps the location of its first + * \param offset: an index into 'outbuf' which keeps the location of its first * empty location. * - * \param totsize: total size of the buffer in which data is being copied. + * \param totsize: total size of the buffer into which data is being copied. * * \param checkonly: '1' if we do not want to copy data into the buffer and we * want just do a buffer ovreflow control, '0' if data has to be copied as well. @@ -926,7 +925,7 @@ int sock_send(SOCKET sock, SSL *ssl _U_NOSSL_, const char *buffer, size_t size, * larger than 'errbuflen - 1' because the last char is reserved for the string terminator. * * \return '0' if everything is fine, '-1' if some errors occurred. The error message - * is returned in the 'errbuf' variable. When the function returns, 'tempbuf' will + * is returned in the 'errbuf' variable. When the function returns, 'outbuf' will * have the new string appended, and 'offset' will keep the length of that buffer. * In case of 'checkonly == 1', data is not copied, but 'offset' is updated in any case. * @@ -936,7 +935,7 @@ int sock_send(SOCKET sock, SSL *ssl _U_NOSSL_, const char *buffer, size_t size, * \warning In case of 'checkonly', be carefully to call this function *before* copying * the data into the buffer. Otherwise, the control about the buffer overflow is useless. */ -int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen) +int sock_bufferize(const void *data, int size, char *outbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen) { if ((*offset + size) > totsize) { @@ -946,7 +945,7 @@ int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int } if (!checkonly) - memcpy(tempbuf + (*offset), buffer, size); + memcpy(outbuf + (*offset), data, size); (*offset) += size; diff --git a/sockutils.h b/sockutils.h index e748662e..5e3ac49c 100644 --- a/sockutils.h +++ b/sockutils.h @@ -141,7 +141,7 @@ int sock_close(SOCKET sock, char *errbuf, int errbuflen); int sock_send(SOCKET sock, SSL *, const char *buffer, size_t size, char *errbuf, int errbuflen); -int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen); +int sock_bufferize(const void *data, int size, char *outbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen); int sock_discard(SOCKET sock, SSL *, int size, char *errbuf, int errbuflen); int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage *from, char *errbuf, int errbuflen); int sock_cmpaddr(struct sockaddr_storage *first, struct sockaddr_storage *second);