miax: add additional fix patch and fix broken MD5 on 64bit

Add additional fix patch for compilation error/warning and fix broken
MD5 support on 64bit.

The compilation warning actually discover a very old BUG that produced
wrong MD5 calculation on 64bit systems.

The BUG was caused by the use of unsigned long for uint32. On 64 bit
systems, unsigned long is actually 8 bytes instead of the expected 4
bytes.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
Christian Marangi
2025-11-20 11:38:01 +01:00
parent f6d8ae584f
commit 23cc215273
4 changed files with 201 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=miax
PKG_VERSION:=1.4
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/miax

View File

@@ -0,0 +1,26 @@
From 506ad5d35bd3d9ddf832cae823947e0de111dafa Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Thu, 20 Nov 2025 11:07:23 +0100
Subject: [PATCH 1/3] iax: client: use ssize_t for sendto_t typedef
Linux use ssize_t as the return value of a sendto function. use that to
fix compilation error on new GCC version.
iax/iax.c:418:27: error: assignment to 'sendto_t' {aka 'int (*)(int, const void *, long unsigned int, int, const struct sockaddr *, unsigned int)'} from incompatible pointer type 'ssize_t (*)(int, const void *, size_t, int, const struct sockaddr *, socklen_t)' {aka 'long int (*)(int, const void *, long unsigned int, int, const struct sockaddr *, unsigned int)'} [-Wincompatible-pointer-types]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
iax/iax-client.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/iax/iax-client.h
+++ b/iax/iax-client.h
@@ -77,7 +77,7 @@ struct iax_session;
#ifdef WIN32
typedef int PASCAL (*sendto_t)(SOCKET, const char *, int, int, const struct sockaddr *, int);
#else
-typedef int (*sendto_t)(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
+typedef ssize_t (*sendto_t)(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
#endif
struct iax_event {

View File

@@ -0,0 +1,29 @@
From 5732e9a19676ded26355483ab5239a1c741e5074 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Thu, 20 Nov 2025 11:27:02 +0100
Subject: [PATCH 2/3] iax: frame: make src in ast_frame const
The __FUNCTION__ char is const. Reflect the type in the ast_frame struct
to mute compilation warning.
iax/iax.c: In function '__send_command':
iax/iax.c:779:15: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
779 | f.src = __FUNCTION__;
| ^
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
iax/frame.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/iax/frame.h
+++ b/iax/frame.h
@@ -89,7 +89,7 @@ rame? */
/*! How far into "data" the data really starts */
int offset;
/*! Optional source of frame for debugging */
- char *src;
+ const char *src;
/*! Pointer to actual data */
void *data;
/*! Next/Prev for linking stand alone frames */

View File

@@ -0,0 +1,145 @@
From f2570e2b81d295f52bc5cc6c30fa69fa565c7e42 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Thu, 20 Nov 2025 11:32:02 +0100
Subject: [PATCH 3/3] iax: md5: drop ancient ifdef for uint32 and use uint32_t
Drop an ancient ifdef to handle different size of uint32 on alpha system
and use uinit32_t everywhere.
This was used back in ancient times to handle case where uinit32_t
wasn't 4 bytes.
This now actually cause errors on 64bit system where unsigned long is
actually 8 bytes producing wrong MD5 calculation.
This was spotted by compilation warning:
iax/md5.c: In function 'MD5Update':
iax/md5.c:107:9: warning: 'MD5Transform' reading 128 bytes from a region of size 64 [-Wstringop-overread]
107 | MD5Transform(ctx->buf, (uint32 *) ctx->in);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
that pointed out that we were reading 128 bytes from a region of 64
bytes (the .in value is unsigned char of 64 bytes and MD5Transform
expected 16 entry of 4 bytes).
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
iax/md5.c | 26 +++++++++++++-------------
iax/md5.h | 12 +++---------
2 files changed, 16 insertions(+), 22 deletions(-)
--- a/iax/md5.c
+++ b/iax/md5.c
@@ -49,11 +49,11 @@ void byteReverse(unsigned char *buf, uns
*/
void byteReverse(unsigned char *buf, unsigned longs)
{
- uint32 t;
+ uint32_t t;
do {
- t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
+ t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
- *(uint32 *) buf = t;
+ *(uint32_t *) buf = t;
buf += 4;
} while (--longs);
}
@@ -81,12 +81,12 @@ void MD5Init(struct MD5Context *ctx)
*/
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
- uint32 t;
+ uint32_t t;
/* Update bitcount */
t = ctx->bits[0];
- if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
+ if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
@@ -104,7 +104,7 @@ void MD5Update(struct MD5Context *ctx, u
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
buf += t;
len -= t;
}
@@ -113,7 +113,7 @@ void MD5Update(struct MD5Context *ctx, u
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
buf += 64;
len -= 64;
}
@@ -148,7 +148,7 @@ void MD5Final(unsigned char digest[16],
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
@@ -159,10 +159,10 @@ void MD5Final(unsigned char digest[16],
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
- ((uint32 *) ctx->in)[14] = ctx->bits[0];
- ((uint32 *) ctx->in)[15] = ctx->bits[1];
+ ((uint32_t *) ctx->in)[14] = ctx->bits[0];
+ ((uint32_t *) ctx->in)[15] = ctx->bits[1];
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
@@ -187,9 +187,9 @@ void MD5Final(unsigned char digest[16],
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
-void MD5Transform(uint32 buf[4], uint32 const in[16])
+void MD5Transform(uint32_t buf[4], uint32_t const in[16])
{
- register uint32 a, b, c, d;
+ register uint32_t a, b, c, d;
a = buf[0];
b = buf[1];
--- a/iax/md5.h
+++ b/iax/md5.h
@@ -1,15 +1,9 @@
#ifndef MD5_H
#define MD5_H
-#ifdef __alpha
-typedef unsigned int uint32;
-#else
-typedef unsigned long uint32;
-#endif
-
struct MD5Context {
- uint32 buf[4];
- uint32 bits[2];
+ uint32_t buf[4];
+ uint32_t bits[2];
unsigned char in[64];
};
@@ -17,7 +11,7 @@ void MD5Init(struct MD5Context *context)
void MD5Update(struct MD5Context *context, unsigned char const *buf,
unsigned len);
void MD5Final(unsigned char digest[16], struct MD5Context *context);
-void MD5Transform(uint32 buf[4], uint32 const in[16]);
+void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
/*
* This is needed to make RSAREF happy on some MS-DOS compilers.