Skip to contentSkip to conversation

s390: ensure NUL termination by strncpy()

PATCH In review Roel Kluin 2 participants 2 messages Nov 16, 2009 s390

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 s390: ensure NUL termination by strncpy()

For a larger source string, strncpy only NUL terminates when the size argument is less than the size of the destination string.

---
 arch/s390/kernel/ipl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Is this maybe needed?

arch/s390/kernel/ipl.c +1 -1
index 4890ac6..d52fcb4 100644
@@ -1881,7 +1881,7 @@ void __init setup_ipl(void)
 		break;
 	case IPL_TYPE_NSS:
 		strncpy(ipl_info.data.nss.name, kernel_nss_name,
-			sizeof(ipl_info.data.nss.name));
+			sizeof(ipl_info.data.nss.name) - 1);
 		break;
 	case IPL_TYPE_UNKNOWN:
 		/* We have no info to copy */
#1 lore raw
Quoted 9 lines · Roel Kluin

For a larger source string, strncpy only NUL terminates when the size argument is less than the size of the destination string.

---
 arch/s390/kernel/ipl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Is this maybe needed?

No, kernel_nss_name as well as the data.nss.name char array within ipl_info have the same size. So it will always fit and it is always NUL terminated.

Maybe it should be changed to a simple memcpy, like we have it at a second place in the same file. I think that's up to Michael.

Quoted 13 lines
arch/s390/kernel/ipl.c +1 -1
index 4890ac6..d52fcb4 100644
@@ -1881,7 +1881,7 @@ void __init setup_ipl(void)
 		break;
 	case IPL_TYPE_NSS:
 		strncpy(ipl_info.data.nss.name, kernel_nss_name,
-			sizeof(ipl_info.data.nss.name));
+			sizeof(ipl_info.data.nss.name) - 1);
 		break;
 	case IPL_TYPE_UNKNOWN:
 		/* We have no info to copy */