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

GCC 13 realloc warning fix for bctbx_concat/belle_sip_concat #19

Open
fweimer-rh opened this issue Jan 18, 2023 · 0 comments
Open

GCC 13 realloc warning fix for bctbx_concat/belle_sip_concat #19

fweimer-rh opened this issue Jan 18, 2023 · 0 comments
Labels

Comments

@fweimer-rh
Copy link

Context

We package belle-sip in Fedora. We have an older version which does not use the split bctoolbox yet.

General information

Fedora 38

Expected behaviour

Package builds with GCC 13.

To Reproduce

Build the software with GCC 13.

belle_sip_utils.c: In function 'belle_sip_concat':
belle_sip_utils.c:555:31: error: pointer 'result_71' may be used after 'realloc' [-Werror=use-after-free]
  555 |               wp = newp + (wp - result);
      |                           ~~~~^~~~~~~~~
belle_sip_utils.c:549:31: note: call to 'realloc' here
  549 |               newp = (char *) realloc (result, allocated);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Additional context

This seems to fix it:

diff --git a/src/belle_sip_utils.c b/src/belle_sip_utils.c
index 9688a2b..51ec3e9 100644
--- a/src/belle_sip_utils.c
+++ b/src/belle_sip_utils.c
@@ -545,6 +545,7 @@ char * belle_sip_concat (const char *str, ...) {
           /* Resize the allocated memory if necessary.  */
           if (wp + len + 1 > result + allocated)
             {
+             ptrdiff_t wp_offset = wp - result;
               allocated = (allocated + len) * 2;
               newp = (char *) realloc (result, allocated);
               if (newp == NULL)
@@ -552,7 +553,7 @@ char * belle_sip_concat (const char *str, ...) {
                   free (result);
                   return NULL;
                 }
-              wp = newp + (wp - result);
+              wp = newp + wp_offset;
               result = newp;
             }
           memcpy (wp, s, len);

A similar patch is apparently needed for bctoolbox.

SDK logs URL

No response

@fweimer-rh fweimer-rh added the bug label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant