--- apps/x509.c.orig	2011-09-23 23:48:59.000000000 +0200
+++ apps/x509.c	2012-03-04 15:48:07.000000000 +0100
@@ -899,7 +899,7 @@
 
 				OPENSSL_free(m);
 				}
-			else if (text == i)
+			else if (text == i && !x509req )
 				{
 				X509_print_ex(out,x,nmflag, certflag);
 				}
@@ -1001,10 +1001,18 @@
 					ERR_print_errors(bio_err);
 					goto end;
 					}
+                                if (text)
+                                        X509_REQ_print(out,rq);
 				if (!noout)
 					{
-					X509_REQ_print(out,rq);
-					PEM_write_bio_X509_REQ(out,rq);
+                                        if 	(outformat == FORMAT_ASN1)
+                                                i2d_X509_REQ_bio(out,rq);
+                                        else if (outformat == FORMAT_PEM) {
+                                                PEM_write_bio_X509_REQ(out,rq);
+                                        } else {
+                                                BIO_printf(bio_err,"bad output format specified for outfile\n");
+                                                goto end;
+                                                }
 					}
 				noout=1;
 				}
