Skip to content
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

constants: increase SCTP_DIAG_INFO_LEN to accommodate longer file paths #521

Merged
merged 1 commit into from
Aug 26, 2020

Conversation

tp-m
Copy link
Contributor

@tp-m tp-m commented Aug 25, 2020

Can happen when used as a meson subproject, for example.

Fixes "‘%s’ directive output truncated writing XX bytes into
a region of size NN [-Wformat-truncation=]" compiler warnings.

@tuexen
Copy link
Member

tuexen commented Aug 26, 2020

I'm using snprintf() intentionally, I want the output to be truncated. On which platform and which compiler produces a warning? What are the warnings? I thought the warning is suppressed by checking the return value of snprintf(). That is why I'm using SCTP_SNPRINTF()...

@tp-m
Copy link
Contributor Author

tp-m commented Aug 26, 2020

This happens on debian sid (Linux) with gcc (Debian 10.1.0-6) 10.1.0.

Warnings are:

[3547/4426] Compiling C object subprojects/gst-plugins-bad/ext/sctp/usrsctp/libusrsctp-static.a.p/usrsctplib_netinet_sctp_input.c.o
In file included from ../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os.h:74,
                 from ../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:40:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c: In function ‘sctp_process_control’:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 20 bytes into a region of size 6 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:4926:5: note: in expansion of macro ‘SCTP_SNPRINTF’
 4926 |     SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |     ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 143 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:4926:5: note: in expansion of macro ‘SCTP_SNPRINTF’
 4926 |     SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |     ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 20 bytes into a region of size 6 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:4882:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 4882 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 143 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:4882:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 4882 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c: In function ‘sctp_common_input_processing’:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 28 bytes into a region of size 6 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:5914:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 5914 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 151 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:5914:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 5914 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 28 bytes into a region of size 6 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:5997:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 5997 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 151 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:5997:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 5997 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 28 bytes into a region of size 6 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:6083:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 6083 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 151 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_input.c:6083:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 6083 |    SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
[3593/4426] Compiling C object subprojects/gst-plugins-bad/ext/sctp/usrsctp/libusrsctp-static.a.p/usrsctplib_netinet_sctp_output.c.o
In file included from ../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os.h:74,
                 from ../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:40:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c: In function ‘sctp_send_initiate_ack’:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 22 bytes into a region of size 11 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:6020:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 6020 |    SCTP_SNPRINTF(msg, sizeof(msg), "%s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 140 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:6020:4: note: in expansion of macro ‘SCTP_SNPRINTF’
 6020 |    SCTP_SNPRINTF(msg, sizeof(msg), "%s:%d at %s", __FILE__, __LINE__, __func__);
      |    ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c: In function ‘sctp_lower_sosend’:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 17 bytes into a region of size 10 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:14633:6: note: in expansion of macro ‘SCTP_SNPRINTF’
14633 |      SCTP_SNPRINTF(msg, sizeof(msg),
      |      ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 136 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:14633:6: note: in expansion of macro ‘SCTP_SNPRINTF’
14633 |      SCTP_SNPRINTF(msg, sizeof(msg),
      |      ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c: In function ‘sctp_sendall_iterator’:
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: warning: ‘%s’ directive output truncated writing 21 bytes into a region of size 11 [-Wformat-truncation=]
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:7271:7: note: in expansion of macro ‘SCTP_SNPRINTF’
 7271 |       SCTP_SNPRINTF(msg, sizeof(msg),
      |       ^~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_os_userspace.h:809:6: note: ‘snprintf’ output 139 bytes into a destination of size 128
  809 |  if (snprintf(data, __VA_ARGS__) < 0) {     \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../home/tpm/Devel/gst-build/subprojects/gst-plugins-bad/ext/sctp/usrsctp/usrsctplib/netinet/sctp_output.c:7271:7: note: in expansion of macro ‘SCTP_SNPRINTF’
 7271 |       SCTP_SNPRINTF(msg, sizeof(msg),
      |       ^~~~~~~~~~~~~

@tuexen
Copy link
Member

tuexen commented Aug 26, 2020

I guess it is time to disable the warning... It doesn't make sense, since I want to output to be truncated if it is too long...

@tp-m
Copy link
Contributor Author

tp-m commented Aug 26, 2020

I guess it is time to disable the warning... It doesn't make sense, since I want to output to be truncated if it is too long...

Is there a reason to keep the message buffer length so small though? I mean, why not enlarge it? Performance concerns or?

@tuexen
Copy link
Member

tuexen commented Aug 26, 2020

The buffer is (often) allocated on the stack and the sources are shared with the FreeBSD kernel stack. At least in the kernel, the space on the stack is limited.

I'm fine with the string being truncated, that is why I'm using snprintf(). gcc seems not to like this, don't know why. At some point of time, it was OK to check the return code to avoid this warning. However, in the FreeBSD kernel, snprintf() never fails. So I introduced a macro to deal with this. But newer gcc versions seem not to support the usage of snprintf() with truncation intended...

@tp-m
Copy link
Contributor Author

tp-m commented Aug 26, 2020

Ah, I see. Thanks for the explanation.

One could allow a larger buffer #if defined(__Userspace__) but I guess that wouldn't really solve the issue in general, just for my use case :)
The paths for kernel builds are not that long. So it fixes it in the general case, I guess...

@tuexen
Copy link
Member

tuexen commented Aug 26, 2020

We could change it for the userland stack...

Can you use something like

#if defined(__Userspace__)
#define SCTP_DIAG_INFO_LEN 256
#else
#define SCTP_DIAG_INFO_LEN 128
#endif

.. but only for the userspace stack.

Can happen when used as a meson subproject, for example.

Fixes "‘%s’ directive output truncated writing XX bytes into
a region of size NN [-Wformat-truncation=]" compiler warnings
with gcc10 on Linux.
@tuexen tuexen merged commit df3fb4b into sctplab:master Aug 26, 2020
@tuexen
Copy link
Member

tuexen commented Aug 26, 2020

Thanks for the patch.

@tp-m tp-m deleted the sctp-diag-info-len branch August 26, 2020 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants