diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2017-11-22 15:22:51 -0600 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2017-11-28 10:20:32 -0500 |
commit | 75f0cfee9e5d1eb6c2f76d1898976391c1ab5031 (patch) | |
tree | 424feecb13646fccdaf97119864d6bafe6200e3a /src | |
parent | 929920660d1cc1d58a5dbd65be389ccfc76e515d (diff) | |
download | talos-hostboot-75f0cfee9e5d1eb6c2f76d1898976391c1ab5031.tar.gz talos-hostboot-75f0cfee9e5d1eb6c2f76d1898976391c1ab5031.zip |
Fix strncpy from padding past the actual max size
In the padding portion of strncpy an array was used on a
pointer that was incremented N times. Resulting in padding
N bytes past the max
Change-Id: Icb075a234f456f9763c9712e1d6c78c947efdce1
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/50001
Reviewed-by: Martin Gloff <mgloff@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/string_utils.C | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/lib/string_utils.C b/src/lib/string_utils.C index 27d9228fb..6e7bcd804 100644 --- a/src/lib/string_utils.C +++ b/src/lib/string_utils.C @@ -159,20 +159,17 @@ extern "C" int strncmp(const char* a, const char* b, size_t l) extern "C" char* strncpy(char* d, const char* s, size_t l) { char* d1 = d; - size_t len = 0; - - do + while ( (l > 0) && (*s != '\0') ) { - if (len++ >= l) break; - *d1 = *s; - if (*s == '\0') break; - d1++; s++; - } while(1); + *d1++ = *s++; + --l; + } // pad the remainder - while( len < l ) + while (l > 0) { - d1[len++] = '\0'; + *d1++ = '\0'; + --l; } return d; |