Skip to contentSkip to conversation

isimodem: gprs-context: properly null terminate cd->password

PATCH Applied James Prestwood 2 participants 4 messages Jun 17, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 isimodem: gprs-context: properly null terminate cd->password

It looks like a previous line was copied and cd->username was re-terminated instead of password. This also fixes a compiler error when using GCC 9:

In function ‘strncpy’,
inlined from ‘isi_gprs_activate_primary’ at drivers/isimodem/gprs-context.c:546:3:
/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output may be truncated copying 53 bytes from a string of length 255 [-Werror=stringop-truncation]

  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 drivers/isimodem/gprs-context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/isimodem/gprs-context.c +1 -1
index 9ccc7f15..4076ed8b 100644
@@ -544,7 +544,7 @@ static void isi_gprs_activate_primary(struct ofono_gprs_context *gc,
 		strncpy(cd->username, ctx->username, GPDS_MAX_USERNAME_LENGTH);
 		cd->username[GPDS_MAX_USERNAME_LENGTH] = '\0';
 		strncpy(cd->password, ctx->password, GPDS_MAX_PASSWORD_LENGTH);
-		cd->username[GPDS_MAX_PASSWORD_LENGTH] = '\0';
+		cd->password[GPDS_MAX_PASSWORD_LENGTH] = '\0';
 	}
 
 	cd->pep = g_isi_pep_create(cd->idx, NULL, NULL);
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/2 isimodem: voicecall: fix strncpy compiler error (GCC 9)

GCC complains that the destination buffer equals the size to copy:

In function ‘strncpy’,
inlined from ‘isi_call_any_address_sb_proc.isra.0’ at drivers/isimodem/voicecall.c:230:2:
/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 20 equals destination size [-Werror=stringop-truncation]

  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 drivers/isimodem/voicecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/isimodem/voicecall.c +1 -1
index 9a63f100..3fb150f6 100644
@@ -227,7 +227,7 @@ static void isi_call_any_address_sb_proc(struct isi_voicecall *ivc,
 
 	call->addr_type = type | 0x80;
 	call->presentation = pres;
-	strncpy(call->address, addr, sizeof(call->address));
+	strncpy(call->address, addr, sizeof(call->address) - 1);
 
 	g_free(addr);
 }
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH 2/2] isimodem: voicecall: fix strncpy compiler error (GCC 9)

Hi James,

Quoted 16 lines · James Prestwood

GCC complains that the destination buffer equals the size to copy:

In function ‘strncpy’,
inlined from ‘isi_call_any_address_sb_proc.isra.0’ at drivers/isimodem/voicecall.c:230:2:
/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 20 equals destination size [-Werror=stringop-truncation]

   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
  drivers/isimodem/voicecall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/isimodem/voicecall.c +0 -0
index 9a63f100..3fb150f6 100644

drivers/isimodem/voicecall.c static void isi_call_any_address_sb_proc(struct isi_voicecall *ivc, · line 230

Quoted 5 lines
drivers/isimodem/voicecall.c +1 -1
@@ -227,7 +227,7 @@ static void isi_call_any_address_sb_proc(struct isi_voicecall *ivc,
 
  	call->addr_type = type | 0x80;
  	call->presentation = pres;
-	strncpy(call->address, addr, sizeof(call->address));
+	strncpy(call->address, addr, sizeof(call->address) - 1);

Note that this doesn't null terminate call->address in all cases... This file is full of these, so the sanest approach might be to use l_strlcpy.

drivers/isimodem/voicecall.c static void isi_call_any_address_sb_proc(struct isi_voicecall *ivc,

Quoted 4 lines
drivers/isimodem/voicecall.c +0 -0
  	g_free(addr);
  }
 

Regards,
-Denis

#3 lore raw
In reply to James Prestwood

Hi James,

Quoted 12 lines · James Prestwood

It looks like a previous line was copied and cd->username was re-terminated instead of password. This also fixes a compiler error when using GCC 9:

In function ‘strncpy’,
inlined from ‘isi_gprs_activate_primary’ at drivers/isimodem/gprs-context.c:546:3:
/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output may be truncated copying 53 bytes from a string of length 255 [-Werror=stringop-truncation]

   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
  drivers/isimodem/gprs-context.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis