All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux.com>
To: sparclinux@vger.kernel.org
Subject: Re: [PATCH] arch/sparc: additional len check in loop for prom_getbootargs
Date: Tue, 13 Nov 2012 05:29:55 +0000	[thread overview]
Message-ID: <50A1DAD3.40305@asianux.com> (raw)
In-Reply-To: <509B29F3.2040006@asianux.com>

于 2012年11月13日 13:06, David Miller 写道:
> From: Chen Gang <gang.chen@asianux.com>
> Date: Tue, 13 Nov 2012 12:46:17 +0800
> 
>> 1) although I agree with what you said.
>>
>> 2) but for the patch code:
>>    after "*cp++ = ' ';", also need "break checking" for "for (; ;)" outside of "while()"
>>
>> 3) please check, and still it will be better to notice coding style, too.
> 
> Why is every single one of your replies a set of 3 bullet points?  You
> aren't giving a PowerPoint presentation.
> 
> Just talk and discuss things normally, using sentences and paragraphs
> for your structure.
> 
> Everything you say and do looks very unnatural, awkward, and forced.
> 
> 

 Excuse me,, my English is not quite well, just as you said (I need improving)


 after "*cp++ = ' ';" at line 42, also need "break checking" for "for (; ;)" outside of "while()"

 the reply from sam not check it, (the patch what I sent check it).

 this is the original source code of function prom_getbootargs in arch/sparc/prom/bootstr_32.c.
------------------------------------------------------------------------------------------------
 27         case PROM_V0:
 28                 cp = barg_buf;
 29                 /* Start from 1 and go over fd(0,0,0)kernel */
 30                 for(iter = 1; iter < 8; iter++) {
 31                         arg = (*(romvec->pv_v0bootargs))->argv[iter];
 32                         if (arg = NULL)
 33                                 break;
 34                         while(*arg != 0) {
 35                                 /* Leave place for space and null. */
 36                                 if(cp >= barg_buf + BARG_LEN-2){
 37                                         /* We might issue a warning here. */
 38                                         break;
 39                                 }
 40                                 *cp++ = *arg++;
 41                         }
 42                         *cp++ = ' ';
 43                 }
 44                 *cp = 0;
 45                 break;
---------------------------------------------------------------------------------------------------


this is the original reply from sam:
--------------------------------------------------------------------------------------------------
Hi Cheng.
On Thu, Nov 08, 2012 at 11:41:39AM +0800, Chen Gang wrote:
>
>   when cp >= barg_buf + BARG_LEN-2, it only break internel loop (while)
>   but outside loop (for) still has effect, and "*cp++ = ' '" repeating
>   so need additional checking for it.
>
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>

I wonder how you found this bug?!?!
Anyway please consider this alternative fix:

diff --git a/arch/sparc/prom/bootstr_32.c b/arch/sparc/prom/bootstr_32.c
index f5ec32e..4ce602f 100644
--- a/arch/sparc/prom/bootstr_32.c
+++ b/arch/sparc/prom/bootstr_32.c
@@ -31,14 +31,10 @@ prom_getbootargs(void)
 			arg = (*(romvec->pv_v0bootargs))->argv[iter];
 			if (arg = NULL)
 				break;
-			while(*arg != 0) {
-				/* Leave place for space and null. */
-				if(cp >= barg_buf + BARG_LEN-2){
-					/* We might issue a warning here. */
-					break;
-				}
+			while (*arg != 0 && cp < (barg_buf + BARG_LEN - 2))
 				*cp++ = *arg++;
-			}
+
+			/* Append trailing space + null */
 			*cp++ = ' ';
 		}
 		*cp = 0;


Adding the conditional inside the while loop makes
the logic simpler. And the patch actually deletes more lines than it adds.
And please take care to follow coding style too. In particular spaces around operators.

The old code does not follow coding style - but this is no excuse.

Note - the above is not even build tested!

If you use the above code-snippet you can add my:
Acked-by: Sam Ravnborg <sam@ravnborg.org>

	Sam
------------------------------------------------------------------------------------------




-- 
Chen Gang

Asianux Corporation

      parent reply	other threads:[~2012-11-13  5:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-08  3:41 [PATCH] arch/sparc: additional len check in loop for prom_getbootargs Chen Gang
2012-11-08 16:33 ` Sam Ravnborg
2012-11-09  3:15 ` Chen Gang
2012-11-09  3:16 ` David Miller
2012-11-09  3:25 ` Chen Gang
2012-11-09  5:06 ` Julian Calaby
2012-11-09  5:29 ` Chen Gang
2012-11-13  3:06 ` Chen Gang
2012-11-13  3:25 ` Chen Gang
2012-11-13  4:46 ` Chen Gang
2012-11-13  5:06 ` David Miller
2012-11-13  5:29 ` Chen Gang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50A1DAD3.40305@asianux.com \
    --to=gang.chen@asianux.com \
    --cc=sparclinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.