Skip to contentSkip to conversation

tlshd: fix max config file size comparison

PATCH In review Jeff Layton 2 participants 2 messages Jun 20, 2023 Handshake upcall for transport layer security

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tlshd: fix max config file size comparison

gcc throws a warning on 32-bit x86 because of signedness mismatch:

config.c:155:52: error: comparison of integer expressions of different signedness: '__off_t' {aka 'long int'} and 'unsigned int' [-Werror=sign-compare]
155 | if (statbuf.st_size < 0 || statbuf.st_size > UINT_MAX) {
| ^

st_size is a signed value (off_t), but UINT_MAX is unsigned.

Change it to compare against INT_MAX instead. This technically cuts the max size of the config file in half to only 2GB, but I don't think we'll miss it.

---
 src/tlshd/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/tlshd/config.c +1 -1
index 87cc4018733b..bdab98b9fba4 100644
@@ -152,7 +152,7 @@ static bool tlshd_config_read_datum(const char *pathname, gnutls_datum_t *data,
 		tlshd_log_perror("stat");
 		goto out_close;
 	}
-	if (statbuf.st_size < 0 || statbuf.st_size > UINT_MAX) {
+	if (statbuf.st_size < 0 || statbuf.st_size > INT_MAX) {
 		tlshd_log_error("Bad config file size: %lld", statbuf.st_size);
 		goto out_close;
 	}
Signature · 1 line
2.41.0
#1 lore raw
Quoted 28 lines · Jeff Layton

gcc throws a warning on 32-bit x86 because of signedness mismatch:

config.c:155:52: error: comparison of integer expressions of different signedness: '__off_t' {aka 'long int'} and 'unsigned int' [-Werror=sign-compare]
155 | if (statbuf.st_size < 0 || statbuf.st_size > UINT_MAX) {
| ^

st_size is a signed value (off_t), but UINT_MAX is unsigned.

Change it to compare against INT_MAX instead. This technically cuts the max size of the config file in half to only 2GB, but I don't think we'll miss it.

---
src/tlshd/config.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
src/tlshd/config.c +0 -0
index 87cc4018733b..bdab98b9fba4 100644

src/tlshd/config.c static bool tlshd_config_read_datum(const char *pathname, gnutls_datum_t *data, · line 158

Quoted 8 lines
src/tlshd/config.c +1 -1
@@ -152,7 +152,7 @@ static bool tlshd_config_read_datum(const char *pathname, gnutls_datum_t *data,
 tlshd_log_perror("stat");
 goto out_close;
 }
- if (statbuf.st_size < 0 || statbuf.st_size > UINT_MAX) {
+ if (statbuf.st_size < 0 || statbuf.st_size > INT_MAX) {
 tlshd_log_error("Bad config file size: %lld", statbuf.st_size);
 goto out_close;
 }

Opened version ktls-utils-0.10-dev and applied this fix to oracle/ktls-utils.

--
Chuck Lever