From 503f00940d624ae697b9360d61893a3ad8b5219e Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Thu, 20 Jan 2022 09:14:10 +0100
Subject: [PATCH 1/6] Fix warnings about possibly non-terminated strings
dcapPasswd.c: In function 'main':
dcapPasswd.c:56:5: warning: 'strncpy' specified bound 100 equals destination size [-Wstringop-truncation]
56 | strncpy(savepasswd, (char*)crypt(newpasswd, user), 100);
| ^
dcapPasswd.c:35:7: warning: 'strncpy' specified bound 100 equals destination size [-Wstringop-truncation]
35 | strncpy(savepasswd, (char*)crypt(newpasswd, user), 100);
| ^
---
plugins/telnet/dcapPasswd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/plugins/telnet/dcapPasswd.c b/plugins/telnet/dcapPasswd.c
index 600badc..745a487 100644
--- a/plugins/telnet/dcapPasswd.c
+++ b/plugins/telnet/dcapPasswd.c
@@ -33,6 +33,7 @@ int main (int argn, char **argv) {
/* Change entry if found. */
if (strcmp(p->pw_name, user) == 0) {
strncpy(savepasswd, (char*)crypt(newpasswd, user), 100);
+ savepasswd[99] = '\0';
p->pw_passwd = savepasswd;
p->pw_uid = 100;
p->pw_gid = 100;
@@ -54,6 +55,7 @@ int main (int argn, char **argv) {
p = (struct passwd *) malloc (sizeof (struct passwd));
p->pw_name = user;
strncpy(savepasswd, (char*)crypt(newpasswd, user), 100);
+ savepasswd[99] = '\0';
p->pw_passwd = savepasswd;
p->pw_uid = 100;
p->pw_gid = 100;
From 60aa1d557b586a975da4f1198be4b121f9a6ad46 Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Thu, 20 Jan 2022 09:28:25 +0100
Subject: [PATCH 2/6] Add parentethes around assignment used as truth value
dcap.c: In function 'sayHello':
dcap.c:769:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
769 | while (i = strchr(patch, '\"')) {
| ^
---
src/dcap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/dcap.c b/src/dcap.c
index ce4d311..e753efc 100644
--- a/src/dcap.c
+++ b/src/dcap.c
@@ -766,7 +766,7 @@ sayHello(int fd, ioTunnel *en)
context = dc_char_buf_create();
getRevision(&rev);
patch = strdup(rev.Patch);
- while (i = strchr(patch, '\"')) {
+ while ((i = strchr(patch, '\"'))) {
*i = '\'';
}
From d3f81cc12b2eb735be02827c26ab93b1d1a7db33 Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Thu, 20 Jan 2022 09:29:59 +0100
Subject: [PATCH 3/6] Fix warning about bound of copy based on source length
dcap_error.c: In function 'dc_setServerError':
dcap_error.c:224:9: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
224 | strncpy(p, msg, len);
| ^
dcap_error.c:219:15: note: length computed here
219 | len = strlen(msg);
| ^~~~~~~~~~~
---
src/dcap_error.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/src/dcap_error.c b/src/dcap_error.c
index 9e7ddfd..8b06c9d 100644
--- a/src/dcap_error.c
+++ b/src/dcap_error.c
@@ -49,7 +49,7 @@ __dc_errno()
{
int *en;
- /* only one thread allowed to kreate key*/
+ /* only one thread allowed to create key */
m_lock(&kLock);
if(!err_once) {
t_keycreate(&err_key, NULL);
@@ -71,7 +71,7 @@ __dc_srvMessage()
{
char **msg;
- /* only one thread allowed to create key*/
+ /* only one thread allowed to create key */
m_lock(&kLock);
if(!msg_once) {
t_keycreate(&srvMessage_key, NULL);
@@ -92,7 +92,7 @@ static char * dc_errno2srvMessage()
{
char *sPtr;
- /* only one thread allowed to kreate key*/
+ /* only one thread allowed to create key */
m_lock(&kLock);
if(!msgPtr_once) {
t_keycreate(&srvMessagePtr_key, NULL);
@@ -194,8 +194,7 @@ dc_error(const char *msg)
void dc_setServerError(const char *msg)
{
- char *p;
- int len;
+ char *p;
if(srvMessage != NULL) {
free(srvMessage);
@@ -209,20 +208,15 @@ void dc_setServerError(const char *msg)
errno = EIO;
- /* 'p' will point to the buffer for error mesage */
+ /* 'p' will point to the buffer for error message */
#ifdef _REENTRANT
p = dc_errno2srvMessage();
#else
p = srvConstMessage;
#endif /* _REENTRANT */
- len = strlen(msg);
- if(len > DC_MAX_SRV_ERR_MSG) {
- len = DC_MAX_SRV_ERR_MSG;
- }
-
- strncpy(p, msg, len);
- p[len] = '\0';
+ strncpy(p, msg, DC_MAX_SRV_ERR_MSG);
+ p[DC_MAX_SRV_ERR_MSG] = '\0';
/* there is no need to free 'p', while we get it already allocated */
}
@@ -230,7 +224,7 @@ void dc_setServerError(const char *msg)
const char * dc_strerror(int errnum)
{
- const char *p;
+ const char *p;
if( (errnum > DEMAXERRORNUM) || (errnum < DEOK) ) {
return "Unknown error";
@@ -238,9 +232,9 @@ const char * dc_strerror(int errnum)
if(errnum == DESRVMSG) {
#ifdef _REENTRANT
- p = dc_errno2srvMessage();
+ p = dc_errno2srvMessage();
#else
- p = srvConstMessage;
+ p = srvConstMessage;
#endif /* _REENTRANT */
}else{
p = dcap_errlist[errnum];
From 8f079f8e0a816aff37692b7cf6766b1a68ac7ee4 Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Thu, 20 Jan 2022 09:32:56 +0100
Subject: [PATCH 4/6] Fix warning about uninitialized value.
In function 'find_lru_buf',
inlined from 'extract_lru_cb' at dcap_lcb.c:510:15,
inlined from 'build_from_extracted_lru_cb' at dcap_lcb.c:492:14,
inlined from 'update_currentcb_by_reading' at dcap_lcb.c:436:8,
inlined from 'ensure_data_in_currentcb' at dcap_lcb.c:352:2,
inlined from 'dc_lcb_read' at dcap_lcb.c:288:2:
dcap_lcb.c:534:27: warning: 'maxage' may be used uninitialized in this function [-Wmaybe-uninitialized]
534 | if( i == 1 || age > maxage) {
| ~~~~^~~~~~~~
dcap_lcb.c: In function 'dc_lcb_read':
dcap_lcb.c:527:24: note: 'maxage' was declared here
527 | unsigned long age, maxage;
---
src/dcap_lcb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/dcap_lcb.c b/src/dcap_lcb.c
index 701835a..e5870ce 100644
--- a/src/dcap_lcb.c
+++ b/src/dcap_lcb.c
@@ -524,7 +524,7 @@ cbindex_t *find_lru_buf(local_cache_buffer_t *lb)
{
int i;
cbindex_t *cb, *lru_cb = NULL;
- unsigned long age, maxage;
+ unsigned long age, maxage = 0;
/* The algorithm requires that the first buffer (index 0) of the
* array is never returned */
From a04b3ba5eee7dc941d6debd3b34d6ef06765d50b Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Thu, 20 Jan 2022 09:34:57 +0100
Subject: [PATCH 5/6] Fix warning about writing outside memory allocation.
Allocated memory size miscalculated due to missing parenthees.
dcap_url.c:222:17: warning: 'memcpy' writing 6 bytes into a region of size between 1 and 2 [-Wstringop-overflow=]
222 | memcpy(url->host, DEFAULT_DOOR , def_door_len);
| ^
dcap_url.c:215:37: note: destination object of size [1, 2] allocated by 'malloc'
215 | url->host = (char *)malloc( def_door_len + host_len + host_len > 0 ? 2 : 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dcap_url.c:224:25: warning: 'memcpy' writing 1 byte into a region of size 0 [-Wstringop-overflow=]
224 | memcpy(url->host + def_door_len, ".", 1);
| ^
dcap_url.c:215:37: note: at offset 6 into destination object of size [1, 2] allocated by 'malloc'
215 | url->host = (char *)malloc( def_door_len + host_len + host_len > 0 ? 2 : 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
src/dcap_url.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/dcap_url.c b/src/dcap_url.c
index e807c58..67d2f5f 100644
--- a/src/dcap_url.c
+++ b/src/dcap_url.c
@@ -212,7 +212,7 @@ dcap_url* dc_getURL( const char *path )
def_door_len = strlen(DEFAULT_DOOR);
- url->host = (char *)malloc( def_door_len + host_len + host_len > 0 ? 2 : 1);
+ url->host = (char *)malloc( def_door_len + host_len + (host_len > 0 ? 2 : 1));
if(url->host == NULL) {
dc_debug(DC_ERROR, "Failed to allocate hostname for %s", path);
free(url);
From 9089420b185093e0ee4a048eb627887f5ca5fe32 Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Thu, 20 Jan 2022 09:38:06 +0100
Subject: [PATCH 6/6] Fix warning about different declarations of the same
functions This warning is seen on 32 bit architectures. On 64 bit
architectures the types are equivalent.
system_io.h:84:16: warning: type of 'system_ftello64' does not match original declaration [-Wlto-type-mismatch]
84 | extern off64_t system_ftello64(FILE *);
| ^
system_io.c:669:6: note: return value type mismatch
669 | long system_ftello64(FILE *stream)
| ^
system_io.c:669:6: note: type 'long int' should match type 'off64_t'
system_io.c:669:6: note: 'system_ftello64' was previously declared here
system_io.c:669:6: note: code may be misoptimized unless '-fno-strict-aliasing' is used
system_io.h:43:14: warning: type of 'system_lseek64' does not match original declaration [-Wlto-type-mismatch]
43 | extern off_t system_lseek64(int, off64_t, int);
| ^
system_io.c:449:1: note: return value type mismatch
449 | system_lseek64(int fd, off64_t offset, int whence)
| ^
system_io.c:449:1: note: type 'off64_t' should match type 'off_t'
system_io.c:449:1: note: 'system_lseek64' was previously declared here
system_io.c:449:1: note: code may be misoptimized unless '-fno-strict-aliasing' is used
---
src/system_io.c | 2 +-
src/system_io.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/system_io.c b/src/system_io.c
index 67d00a0..ace05c6 100644
--- a/src/system_io.c
+++ b/src/system_io.c
@@ -666,7 +666,7 @@ int system_fflush(FILE *stream)
return initIfNeeded() == 0 ? s_fflush(stream) : -1;
}
-long system_ftello64(FILE *stream)
+off64_t system_ftello64(FILE *stream)
{
return initIfNeeded() == 0 ? s_ftello64(stream) : -1;
}
diff --git a/src/system_io.h b/src/system_io.h
index 0bca25d..f211935 100644
--- a/src/system_io.h
+++ b/src/system_io.h
@@ -40,7 +40,7 @@ extern int system_readv(int, const struct iovec *vector, int count);
extern int system_write(int, const void *, size_t);
extern int system_writev(int, const struct iovec *vector, int count);
extern int system_close(int);
-extern off_t system_lseek64(int, off64_t, int);
+extern off64_t system_lseek64(int, off64_t, int);
extern int system_pread(int, void *, size_t, off_t);
extern int system_pread64(int, void *, size_t, off64_t);
extern int system_pwrite(int, const void *, size_t, off_t);