Sophie

Sophie

distrib > Mageia > 1 > i586 > media > core-updates-src > by-pkgid > 2d27fe3dff73e21c1aac97aebe0dff40 > files > 41

rpm-4.8.1-10.5.mga1.src.rpm

From 7912341b11e3985e035aead29961cabf8b3766c5 Mon Sep 17 00:00:00 2001
From: unknown author <cooker@mandrivalinux.org>
Date: Mon, 5 Jan 2009 13:29:57 +0000
Subject: [PATCH 15/36] 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 816aa81..ceb59c6 100644
--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -94,6 +94,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)
@@ -135,6 +153,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.4.4