new file mode 100644
@@ -0,0 +1,52 @@
+From cf50057e24f2a5aaff6c18e81c27ed8426df1be4 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= <michal@weblate.org>
+Date: Fri, 6 Nov 2026 10:21:53 +0100
+Subject: [PATCH] Bound text backup decoding before copying fields
+
+CVE: CVE-2026-138160
+Upstream-Status: Backport [https://github.com/gammu/gammu/commit/8063e55b23b575ee0dc645ce6e94d8bdade0c0cf]
+
+Dropped test changes during backport
+
+Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
+---
+ libgammu/service/backup/backtext.c | 18 +++++++++++++++++-
+ 1 file changed, 17 insertions(+), 1 deletion(-)
+
+diff --git a/libgammu/service/backup/backtext.c b/libgammu/service/backup/backtext.c
+index c6096749c..46ac756b4 100644
+--- a/libgammu/service/backup/backtext.c
++++ b/libgammu/service/backup/backtext.c
+@@ -238,6 +238,11 @@ static gboolean ReadBackupTextLen(INI_Section *file_info, const char *section, c
+ EncodeUnicode(paramname,myname,strlen(myname));
+ readvalue = INI_GetValue(file_info, section, paramname, UseUnicode);
+ if (readvalue!=NULL) {
++ /* Decoding cannot increase the number of characters. */
++ if (UnicodeLength(readvalue + 2) >= sizeof(decodedvalue) / 2) {
++ myvalue[0] = myvalue[1] = 0;
++ return FALSE;
++ }
+ DecodeUnicodeSpecialChars(decodedvalue, readvalue+2);
+ if ((UnicodeLength(decodedvalue) + 1) * 2 >= maxlen) {
+ decodedvalue[maxlen - 1] = 0;
+@@ -273,8 +278,19 @@ static gboolean ReadBackupTextLen(INI_Section *file_info, const char *section, c
+ strcpy(paramname,myname);
+ readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
+ if (readvalue!=NULL) {
++ size_t decoded_length;
++ if (strlen(readvalue + 1) >= sizeof(decodedvalue)) {
++ myvalue[0] = myvalue[1] = 0;
++ return FALSE;
++ }
+ DecodeSpecialChars(decodedvalue, readvalue + 1);
+- EncodeUnicode(myvalue, decodedvalue, strlen(decodedvalue) - 1);
++ decoded_length = strlen(decodedvalue);
++ /* The decoded string includes a closing quote. */
++ if (decoded_length == 0 || decoded_length - 1 >= maxlen / 2) {
++ myvalue[0] = myvalue[1] = 0;
++ return FALSE;
++ }
++ EncodeUnicode(myvalue, decodedvalue, decoded_length - 1);
+ } else {
+ myvalue[0]=0;
+ myvalue[1]=0;
new file mode 100644
@@ -0,0 +1,107 @@
+From 99104c8b758c9a130612ba3664298579a3d791ad Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= <michal@weblate.org>
+Date: Fri, 6 Nov 2026 10:21:53 +0100
+Subject: [PATCH] Bound text backup decoding before copying fields
+
+CVE: CVE-2026-138160
+Upstream-Status: Backport [https://github.com/gammu/gammu/commit/f224198cc316b590ac0c853aa98cfbcf491a16fe]
+
+Dropped test changes during backport
+
+Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
+---
+ libgammu/service/backup/backtext.c | 56 +++++++++++++++++-------------
+ 1 file changed, 32 insertions(+), 24 deletions(-)
+
+diff --git a/libgammu/service/backup/backtext.c b/libgammu/service/backup/backtext.c
+index 46ac756b4..e05735343 100644
+--- a/libgammu/service/backup/backtext.c
++++ b/libgammu/service/backup/backtext.c
+@@ -231,28 +231,27 @@ static GSM_Error SaveBackupBase64(FILE *file, char *myname, unsigned char *data,
+
+ static gboolean ReadBackupTextLen(INI_Section *file_info, const char *section, const char *myname, char *myvalue, const size_t maxlen, const gboolean UseUnicode)
+ {
+- unsigned char paramname[10000],*readvalue, decodedvalue[10000];
++ unsigned char paramname[10000], *readvalue, *decodedvalue = NULL, *converted = NULL;
++ size_t source_length, decoded_length, converted_length;
+ gboolean ret = TRUE;
+
+ if (UseUnicode) {
+ EncodeUnicode(paramname,myname,strlen(myname));
+ readvalue = INI_GetValue(file_info, section, paramname, UseUnicode);
+ if (readvalue!=NULL) {
+- /* Decoding cannot increase the number of characters. */
+- if (UnicodeLength(readvalue + 2) >= sizeof(decodedvalue) / 2) {
+- myvalue[0] = myvalue[1] = 0;
+- return FALSE;
+- }
++ source_length = UnicodeLength(readvalue + 2);
++ if (source_length > ((size_t)-1) / 2 - 1) goto invalid_text;
++ decodedvalue = malloc((source_length + 1) * 2);
++ if (decodedvalue == NULL) goto invalid_text;
+ DecodeUnicodeSpecialChars(decodedvalue, readvalue+2);
+- if ((UnicodeLength(decodedvalue) + 1) * 2 >= maxlen) {
+- decodedvalue[maxlen - 1] = 0;
+- decodedvalue[maxlen - 2] = 0;
+- dbgprintf(NULL, "String too long!\n");
+- ret = FALSE;
+- }
++ decoded_length = UnicodeLength(decodedvalue);
++ /* The decoded string still includes the closing quote. */
++ if (decoded_length == 0 || decoded_length > maxlen / 2) goto invalid_text;
++ decodedvalue[(decoded_length - 1) * 2] = 0;
++ decodedvalue[(decoded_length - 1) * 2 + 1] = 0;
+ CopyUnicodeString(myvalue, decodedvalue);
+- myvalue[UnicodeLength(myvalue)*2-2]=0;
+- myvalue[UnicodeLength(myvalue)*2-1]=0;
++ free(decodedvalue);
++ decodedvalue = NULL;
+
+ dbgprintf(NULL, "Cfg read: %s\n",DecodeUnicodeString(readvalue));
+ } else {
+@@ -278,19 +277,23 @@ static gboolean ReadBackupTextLen(INI_Section *file_info, const char *section, c
+ strcpy(paramname,myname);
+ readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
+ if (readvalue!=NULL) {
+- size_t decoded_length;
+- if (strlen(readvalue + 1) >= sizeof(decodedvalue)) {
+- myvalue[0] = myvalue[1] = 0;
+- return FALSE;
+- }
++ source_length = strlen(readvalue + 1);
++ if (source_length == (size_t)-1) goto invalid_text;
++ decodedvalue = malloc(source_length + 1);
++ if (decodedvalue == NULL) goto invalid_text;
+ DecodeSpecialChars(decodedvalue, readvalue + 1);
+ decoded_length = strlen(decodedvalue);
+ /* The decoded string includes a closing quote. */
+- if (decoded_length == 0 || decoded_length - 1 >= maxlen / 2) {
+- myvalue[0] = myvalue[1] = 0;
+- return FALSE;
+- }
+- EncodeUnicode(myvalue, decodedvalue, decoded_length - 1);
++ if (decoded_length == 0 || decoded_length > ((size_t)-1) / 2 - 1) goto invalid_text;
++ converted = malloc((decoded_length + 1) * 2);
++ if (converted == NULL) goto invalid_text;
++ EncodeUnicode(converted, decodedvalue, decoded_length - 1);
++ converted_length = UnicodeLength(converted);
++ if (converted_length >= maxlen / 2) goto invalid_text;
++ memcpy(myvalue, converted, (converted_length + 1) * 2);
++ free(decodedvalue);
++ free(converted);
++ decodedvalue = converted = NULL;
+ } else {
+ myvalue[0]=0;
+ myvalue[1]=0;
+@@ -299,6 +302,11 @@ static gboolean ReadBackupTextLen(INI_Section *file_info, const char *section, c
+ }
+ }
+ return ret;
++invalid_text:
++ free(decodedvalue);
++ free(converted);
++ myvalue[0] = myvalue[1] = 0;
++ return FALSE;
+ }
+
+ static GSM_Error SaveVCalDateTime(FILE *file, GSM_DateTime *dt, gboolean UseUnicode)
@@ -8,6 +8,8 @@ SRC_URI = "https://dl.cihar.com/${BPN}/releases/${BP}.tar.xz \
file://gammurc \
file://gammu-smsdrc \
file://0001-allow-build-with-cmake-4.patch \
+ file://CVE-2026-138160_1.patch \
+ file://CVE-2026-138160_2.patch \
"
SRC_URI[sha256sum] = "d8f152314d7e4d3d643610d742845e0a016ce97c234ad4b1151574e1b09651ee"