Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > main-updates-src > by-pkgid > dec4e1edeef36e7485e13bf42f1af5da > files > 50

rpm-4.6.0-14.3mnb2.src.rpm

From d7390b31ac03f11365a2dde2a3963421565df323 Mon Sep 17 00:00:00 2001
From: unknown author <cooker@mandrivalinux.org>
Date: Mon, 5 Jan 2009 13:29:57 +0000
Subject: [PATCH 23/35] forbid badly commented define in spec

---
 build/parseSpec.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/build/parseSpec.c b/build/parseSpec.c
index cf22db3..dad5403 100644
--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -104,6 +104,24 @@ void handleComments(char *s)
 	*s = '\0';
 }
 
+static int begins_with(const char *s, const char *prefix)
+{
+  return strncmp(s, prefix, strlen(prefix)) == 0;
+}
+
+static int isCommentedDefine(const char *line)
+{
+    const char *p = line;
+
+    SKIPSPACE(p);
+    if (*p++ == '#') {
+        SKIPSPACE(p);
+	if (begins_with(p, "%define") &&
+	    isspace(p[strlen("%define")])) return 1;
+    }
+    return 0;
+}
+
 /**
  */
 static void forceIncludeFile(rpmSpec spec, const char * fileName)
@@ -145,6 +163,11 @@ static int copyNextLineFromOFI(rpmSpec spec, OFI_t *ofi)
 	*to++ = '\0';
 	ofi->readPtr = from;
 
+	if (isCommentedDefine(spec->lbuf)) {
+	    rpmlog(RPMLOG_ERR, _("%s:%d: #%%define is forbidden, use #define to comment a %%define\n"), ofi->fileName, ofi->lineNum);
+	    return -1;
+	}
+
 	/* Check if we need another line before expanding the buffer. */
 	for (p = spec->lbuf; *p; p++) {
 	    switch (*p) {
-- 
1.6.1.3