-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tftpd: workaround a stringop-overread warning #11897
Conversation
Nice catch. But since we also need to have a working private header, can't we instead just use that always and then keep the existing approach since our struct has the field last? IOW, can this maybe be an alternative fix? diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c
index 8bcd452d0..75de7f430 100644
--- a/tests/server/tftpd.c
+++ b/tests/server/tftpd.c
@@ -65,15 +65,12 @@
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_TFTP_H
-#include <arpa/tftp.h>
-#else
#include "tftp.h"
-#endif
+
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_SYS_FILIO_H
/* FIONREAD on Solaris 7 */ |
Probably, I have to check. |
Checked: OK. No more warning, compiles and runs tftp tests successfully. I let you apply your preferred fix at your convenience. |
Yeah, that's my preferred route to go with this. |
Using the system's provided arpa/tftp.h and optimizing, GCC 12 detects and reports a stringop-overread warning: tftpd.c: In function ‘write_behind.isra’: tftpd.c:485:12: warning: ‘write’ reading between 1 and 2147483647 bytes from a region of size 0 [-Wstringop-overread] 485 | return write(test->ofile, writebuf, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from tftpd.c:71: /usr/include/arpa/tftp.h:58:30: note: source object ‘tu_data’ of size 0 58 | char tu_data[0]; /* data or error string */ | ^~~~~~~ This occurs because writebuf points to this field and the latter cannot be considered as being of dynamic length because it is not the last field in the structure. Thus it is bound to its declared size. This commit always uses curl's own version of tftp.h where the target field is last in its structure, effectively avoiding the warning. As HAVE_ARPA_TFTP_H is not used anymore, cmake/configure checks for arpa/tftp.h are removed.
The commit in this PR has been completely rewritten to always use curl's own tftp.h. |
Thanks! |
Using the system's provided arpa/tftp.h and optimizing, GCC 12 detects and reports a stringop-overread warning: tftpd.c: In function ‘write_behind.isra’: tftpd.c:485:12: warning: ‘write’ reading between 1 and 2147483647 bytes from a region of size 0 [-Wstringop-overread] 485 | return write(test->ofile, writebuf, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from tftpd.c:71: /usr/include/arpa/tftp.h:58:30: note: source object ‘tu_data’ of size 0 58 | char tu_data[0]; /* data or error string */ | ^~~~~~~ This occurs because writebuf points to this field and the latter cannot be considered as being of dynamic length because it is not the last field in the structure. Thus it is bound to its declared size. This commit always uses curl's own version of tftp.h where the target field is last in its structure, effectively avoiding the warning. As HAVE_ARPA_TFTP_H is not used anymore, cmake/configure checks for arpa/tftp.h are removed. Closes curl#11897
When optimizing, GCC 12 detects and reports a stringop-overread warning:
tftpd.c: In function ‘write_behind.isra’:
tftpd.c:485:12: warning: ‘write’ reading between 1 and 2147483647 bytes from a region of size 0 [-Wstringop-overread]
485 | return write(test->ofile, writebuf, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from tftpd.c:71:
/usr/include/arpa/tftp.h:58:30: note: source object ‘tu_data’ of size 0
58 | char tu_data[0]; /* data or error string */
| ^~~~~~~
This occurs because writebuf points to this field and the latter cannot be considered as being of dynamic length because it is not the last field in the structure. Thus it is bounded to its declared size.
This commit explicitly computes the address to unbind it from the declaration.