aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Gang <gang.chen@asianux.com>2013-05-29 23:35:22 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-19 05:10:29 -0400
commit242ece22f0bd90e237365e51c5bd90a21693d6c3 (patch)
tree7fec0cddbb435a1df405f27f45822cef2e8c3c9d
parentdbebe0da64d0738a21221a7f9d29510b9f29d908 (diff)
arch: sparc: prom: looping issue, need additional length check in the outside looping
When "cp >= barg_buf + BARG_LEN-2", it breaks internel looping 'while', but outside loop 'for' still has effect, so "*cp++ = ' '" will continue repeating which may cause memory overflow. So need additional length check for it in the outside looping. Also beautify the related code which found by "./scripts/checkpatch.pl" Signed-off-by: Chen Gang <gang.chen@asianux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/sparc/prom/bootstr_32.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/arch/sparc/prom/bootstr_32.c b/arch/sparc/prom/bootstr_32.c
index f5ec32e0d419..d2b49d2365e7 100644
--- a/arch/sparc/prom/bootstr_32.c
+++ b/arch/sparc/prom/bootstr_32.c
@@ -23,23 +23,25 @@ prom_getbootargs(void)
23 return barg_buf; 23 return barg_buf;
24 } 24 }
25 25
26 switch(prom_vers) { 26 switch (prom_vers) {
27 case PROM_V0: 27 case PROM_V0:
28 cp = barg_buf; 28 cp = barg_buf;
29 /* Start from 1 and go over fd(0,0,0)kernel */ 29 /* Start from 1 and go over fd(0,0,0)kernel */
30 for(iter = 1; iter < 8; iter++) { 30 for (iter = 1; iter < 8; iter++) {
31 arg = (*(romvec->pv_v0bootargs))->argv[iter]; 31 arg = (*(romvec->pv_v0bootargs))->argv[iter];
32 if (arg == NULL) 32 if (arg == NULL)
33 break; 33 break;
34 while(*arg != 0) { 34 while (*arg != 0) {
35 /* Leave place for space and null. */ 35 /* Leave place for space and null. */
36 if(cp >= barg_buf + BARG_LEN-2){ 36 if (cp >= barg_buf + BARG_LEN - 2)
37 /* We might issue a warning here. */ 37 /* We might issue a warning here. */
38 break; 38 break;
39 }
40 *cp++ = *arg++; 39 *cp++ = *arg++;
41 } 40 }
42 *cp++ = ' '; 41 *cp++ = ' ';
42 if (cp >= barg_buf + BARG_LEN - 1)
43 /* We might issue a warning here. */
44 break;
43 } 45 }
44 *cp = 0; 46 *cp = 0;
45 break; 47 break;