Thanks for the security code suggestions.

The updated patch below:

--- a/osprey/be/cg/cgemit.cxx
+++ b/osprey/be/cg/cgemit.cxx
@@ -3637,6 +3637,39 @@ Modify_Asm_String (char* asm_string, UINT32
position, bool memory,
       asm_string =  Replace_Substring(asm_string, x86pattern, suffix);
     }
   }
+
+  // open64.net bug950. Handle any template modifers
+  // %L,%W,%B,%Q,%S,%T. Referrence i386.c(gcc) print_operand.
+  {
+    char L_suffix[5]={0};
+    char W_suffix[5]={0};
+    char B_suffix[5]={0};
+    char Q_suffix[5]={0};
+    char S_suffix[5]={0};
+    char T_suffix[5]={0};
+    FmtAssert((snprintf(L_suffix,sizeof(L_suffix),"%%L%d",position) >=0) &&
+              (snprintf(W_suffix,sizeof(W_suffix),"%%W%d",position) >=0) &&
+              (snprintf(B_suffix,sizeof(B_suffix),"%%B%d",position) >=0) &&
+              (snprintf(Q_suffix,sizeof(Q_suffix),"%%Q%d",position) >=0) &&
+              (snprintf(S_suffix,sizeof(S_suffix),"%%S%d",position) >=0) &&
+              (snprintf(T_suffix,sizeof(T_suffix),"%%T%d",position) >=0),
+              ("Error, Unable to generate format string in
Modify_Asm_String!\n"));
+    if (strstr(asm_string, L_suffix) != NULL) {
+      asm_string =  Replace_Substring(asm_string, L_suffix, "l");
+    } else if (strstr(asm_string, W_suffix) != NULL) {
+      asm_string =  Replace_Substring(asm_string, W_suffix, "w");
+    } else if (strstr(asm_string, B_suffix) != NULL) {
+      asm_string =  Replace_Substring(asm_string, B_suffix, "b");
+    } else if (strstr(asm_string, Q_suffix) != NULL) {
+      asm_string =  Replace_Substring(asm_string, Q_suffix, "l");
+    } else if (strstr(asm_string, S_suffix) != NULL) {
+      asm_string =  Replace_Substring(asm_string, S_suffix, "s");
+    } else if (strstr(asm_string, T_suffix) != NULL) {
+      asm_string =  Replace_Substring(asm_string, T_suffix, "t");
+    }
+  }
+
+
 #endif // TARG_X8664


Regards
Gang


On Thu, Feb 16, 2012 at 1:14 PM, Jian-Xin Lai <laij...@gmail.com> wrote:

> sprintf should be replace by snprintf and the return value must be
> checked to make sure there is no buffer overflow.
>
> 2012/2/15 Gang Yu <yugang...@gmail.com>:
> > Hi,
> >
> >    Could a gatekeeper please help review the fix for bug950?
> >
> > a sample case:
> >  void
> > outb(unsigned short port, unsigned char val)
> > {
> >   __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
> > }
> >
> > opencc compiles it with:
> > /tmp/ccspin#.i28qhO.s: Assembler messages:
> > /tmp/ccspin#.i28qhO.s:36: Error: invalid character '%' in mnemonic
> > The assembler output:
> >  #   5    __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
> >         movl %edx,%edx                  # [1]
> >         movl %eax,%eax                  # [1]
> >         out%B0 (%dx)
> > is undesired, we miss the handling of op suffix format in ASM template.
> >
> > Suggested patch:
> >
> > --- a/osprey/be/cg/cgemit.cxx
> > +++ b/osprey/be/cg/cgemit.cxx
> > @@ -3637,6 +3637,38 @@ Modify_Asm_String (char* asm_string, UINT32
> position,
> > bool memory,
> >        asm_string =  Replace_Substring(asm_string, x86pattern, suffix);
> >      }
> >    }
> > +
> > +  // open64.net bug950. Handle any template modifers
> > +  // %L,%W,%B,%Q,%S,%T. Referrence i386.c(gcc) print_operand.
> > +  {
> > +    char L_suffix[5];
> > +    char W_suffix[5];
> > +    char B_suffix[5];
> > +    char Q_suffix[5];
> > +    char S_suffix[5];
> > +    char T_suffix[5];
> > +    sprintf(L_suffix,"%%L%d",position);
> > +    sprintf(W_suffix,"%%W%d",position);
> > +    sprintf(B_suffix,"%%B%d",position);
> > +    sprintf(Q_suffix,"%%Q%d",position);
> > +    sprintf(S_suffix,"%%S%d",position);
> > +    sprintf(T_suffix,"%%T%d",position);
> > +    if (strstr(asm_string, L_suffix) != NULL) {
> > +      asm_string =  Replace_Substring(asm_string, L_suffix, "l");
> > +    } else if (strstr(asm_string, W_suffix) != NULL) {
> > +      asm_string =  Replace_Substring(asm_string, W_suffix, "w");
> > +    } else if (strstr(asm_string, B_suffix) != NULL) {
> > +      asm_string =  Replace_Substring(asm_string, B_suffix, "b");
> > +    } else if (strstr(asm_string, Q_suffix) != NULL) {
> > +      asm_string =  Replace_Substring(asm_string, Q_suffix, "l");
> > +    } else if (strstr(asm_string, S_suffix) != NULL) {
> > +      asm_string =  Replace_Substring(asm_string, S_suffix, "s");
> > +    } else if (strstr(asm_string, T_suffix) != NULL) {
> > +      asm_string =  Replace_Substring(asm_string, T_suffix, "t");
> > +    }
> > +  }
> > +
> > +
> >  #endif // TARG_X8664
> >
> > TIA for the review
> >
> >
> > Regards
> > Gang
> >
> >
> ------------------------------------------------------------------------------
> > Virtualization & Cloud Management Using Capacity Planning
> > Cloud computing makes use of virtualization - but cloud computing
> > also focuses on allowing computing to be delivered as a service.
> > http://www.accelacomm.com/jaw/sfnl/114/51521223/
> > _______________________________________________
> > Open64-devel mailing list
> > Open64-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/open64-devel
> >
>
>
>
> --
> Regards,
> Lai Jian-Xin
>
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to