From 1bc8e68e1d8623971e7aee110de3d8b1bf6c14d5 Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Tue, 18 Apr 2017 12:43:51 +0200
Subject: [PATCH] More restriction of referenced project name in TPD files (Bug
 514156)

Change-Id: Idd9de6126af24ec29087fc7a726ab4cb06f808ed
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 compiler2/ProjectGenHelper.cc                 | 17 ++++-
 compiler2/ProjectGenHelper.hh                 |  3 +
 compiler2/makefile.c                          |  2 +-
 compiler2/xpather.cc                          | 67 +++++++++++--------
 compiler2/xpather.h                           |  2 +-
 .../compileonly/mfgen-tpd/Makefile            |  2 +-
 .../mfgen-tpd/diff_tpd_name_error/Makefile    | 46 +++++++++++++
 .../mfgen-tpd/diff_tpd_name_error/a.tpd       | 51 ++++++++++++++
 .../mfgen-tpd/diff_tpd_name_error/b.tpd       | 51 ++++++++++++++
 .../mfgen-tpd/diff_tpd_name_error/c.tpd       | 49 ++++++++++++++
 .../mfgen-tpd/search_paths/main/Main.tpd      |  2 +-
 11 files changed, 258 insertions(+), 34 deletions(-)
 create mode 100644 regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/Makefile
 create mode 100644 regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/a.tpd
 create mode 100644 regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/b.tpd
 create mode 100644 regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/c.tpd

diff --git a/compiler2/ProjectGenHelper.cc b/compiler2/ProjectGenHelper.cc
index dbc62d307..d46293543 100644
--- a/compiler2/ProjectGenHelper.cc
+++ b/compiler2/ProjectGenHelper.cc
@@ -315,7 +315,8 @@ ProjectGenHelper::ProjectGenHelper() :
   Wflag(false),
   Hflag(false),
   projs(),
-  checkedProjs()
+  checkedProjs(),
+  projsNameWithAbsPath()
 {}
 
 void ProjectGenHelper::addTarget(const char* projName)
@@ -787,3 +788,17 @@ bool ProjectGenHelper::DynamicLibraryChecker(const ProjectDescriptor* desc,
   return found;
 }
 
+bool ProjectGenHelper::insertAndCheckProjectName(const char *absPath, const char *projName) {
+  if (projName == NULL) return true;
+  std::string absPathStr = std::string(absPath);
+  std::map<const std::string, const std::string>::iterator it = projsNameWithAbsPath.find(absPathStr);
+   if (it == projsNameWithAbsPath.end()) {
+    projsNameWithAbsPath.insert(std::pair<const std::string, const std::string>(absPathStr, std::string(projName)));
+    return true;
+  } else {
+    if (it->second != projName) {
+      return false;
+    }
+  }
+  return true;
+}
diff --git a/compiler2/ProjectGenHelper.hh b/compiler2/ProjectGenHelper.hh
index 621a2bea1..ae6626f74 100644
--- a/compiler2/ProjectGenHelper.hh
+++ b/compiler2/ProjectGenHelper.hh
@@ -136,6 +136,7 @@ public:
   void print();
   bool sanityCheck(); // tests if the structure generated from TPDs is consistent
   void cleanUp();
+  bool insertAndCheckProjectName(const char *absPath, const char *projName);
 
 private:
     ProjectGenHelper();
@@ -158,6 +159,8 @@ private:
   bool Hflag; // hierarchical make structure
   std::map<const std::string, ProjectDescriptor> projs;
   std::map<const std::string, const ProjectDescriptor*> checkedProjs;
+  // Key is the absolute path name, and the value is the name of the referenced project
+  std::map<const std::string, const std::string> projsNameWithAbsPath;
 };
 
 #endif // _LIB_GEN_HELPER_HH
diff --git a/compiler2/makefile.c b/compiler2/makefile.c
index 0c42522c0..fccbda2f4 100644
--- a/compiler2/makefile.c
+++ b/compiler2/makefile.c
@@ -5345,7 +5345,7 @@ int main(int argc, char *argv[])
     // while the wflag still holds the value of the command line parameter -w
     boolean temp_wflag = FALSE;
 
-    tpd_processed = process_tpd(tpd_file_name, tpd_build_config, file_list_path,
+    tpd_processed = process_tpd(&tpd_file_name, tpd_build_config, file_list_path,
       &argc, &argv, &free_argv, &optind, &ets_name, &project_name,
       &gflag, &sflag, &cflag, &aflag, &pflag,
       &Rflag, &lflag, &mflag, &Pflag, &Lflag, rflag, Fflag, Tflag, output_file, &abs_work_dir, sub_project_dirs, program_name, prj_graph_fp,
diff --git a/compiler2/xpather.cc b/compiler2/xpather.cc
index b3fb6c385..02c652218 100644
--- a/compiler2/xpather.cc
+++ b/compiler2/xpather.cc
@@ -1256,7 +1256,7 @@ static tpd_result config_struct_get_required_configs(struct config_struct* const
   return TPD_SUCCESS;
 }
 
-static tpd_result process_tpd_internal(const char *p_tpd_name, char* tpdName, const char *actcfg,
+static tpd_result process_tpd_internal(const char **p_tpd_name, char* tpdName, const char *actcfg,
   const char *file_list_path, int *p_argc, char ***p_argv, boolean* p_free_argv,
   int *p_optind, char **p_ets_name, char **p_project_name,
   boolean *p_gflag, boolean *p_sflag, boolean *p_cflag, boolean *p_aflag, boolean *preprocess,
@@ -1276,7 +1276,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char* tpdName, co
   struct string2_list* run_command_list, map<cstring, int>& seen_tpd_files, struct string2_list* required_configs, struct string_list** profiled_file_list,
   const char **search_paths, size_t n_search_paths, char** makefileScript, struct config_struct * const all_configs);
 
-extern "C" tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
+extern "C" tpd_result process_tpd(const char **p_tpd_name, const char *actcfg,
   const char *file_list_path, int *p_argc, char ***p_argv, boolean* p_free_argv,
   int *p_optind, char **p_ets_name, char **p_project_name,
   boolean *p_gflag, boolean *p_sflag, boolean *p_cflag, boolean *p_aflag, boolean *preprocess,
@@ -1437,7 +1437,7 @@ failure:
 // process_tpd() may alter these strings; new values will be on the heap.
 // If process_tpd() preserves the content of such a string (e.g. ets_name),
 // it must nevertheless make a copy on the heap via mcopystr().
-static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, const char *actcfg,
+static tpd_result process_tpd_internal(const char **p_tpd_name, char *tpdName, const char *actcfg,
   const char *file_list_path, int *p_argc, char ***p_argv, boolean* p_free_argv,
   int *p_optind, char **p_ets_name, char **p_project_name,
   boolean *p_gflag, boolean *p_sflag, boolean *p_cflag, boolean *p_aflag, boolean *preprocess,
@@ -1469,17 +1469,16 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
     || local_optind == 0); // if called for a referenced project
 
   assert(local_argc   >= local_optind);
-
-  autostring tpd_dir(get_dir_from_path(p_tpd_name));
+  
+  autostring tpd_dir(get_dir_from_path(*p_tpd_name));
   autostring abs_tpd_dir(get_absolute_dir(tpd_dir, NULL, FALSE));
-  boolean free_name = FALSE;
   struct stat buf;
   //Only referenced project, when first try is failed,              and when not absolute path
-  if(0 == local_optind && p_tpd_name != NULL && stat(p_tpd_name, &buf) && tpdName != NULL) {
+  if(0 == local_optind && *p_tpd_name != NULL && stat(*p_tpd_name, &buf) && tpdName != NULL) {
     //Find the first search_path that has the tpd
     for(size_t i = 0; i<n_search_paths; i++) {
       boolean need_slash = search_paths[i][strlen(search_paths[i]) - 1] != '/';
-      NOTIFY("Cannot find %s, trying with %s%s%s\n", p_tpd_name, search_paths[i], need_slash ? "/" : "", tpdName);
+      NOTIFY("Cannot find %s, trying with %s%s%s\n", *p_tpd_name, search_paths[i], need_slash ? "/" : "", tpdName);
       //Create path
       char * prefixed_file_path = (char*)Malloc((strlen(search_paths[i]) + strlen(tpdName) + 1 + need_slash) * sizeof(char));
       strcpy(prefixed_file_path, search_paths[i]);
@@ -1493,16 +1492,16 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
 
       if(!stat(prefixed_file_path, &buf)){
         //Ok, tpd found
-        p_tpd_name = prefixed_file_path;
-        free_name = TRUE;
+        Free(const_cast<char*>(*p_tpd_name));
+        *p_tpd_name = prefixed_file_path;
         NOTIFY("TPD with name %s found at %s.", tpdName, search_paths[i]);
         break;
-      }else {
+      } else {
         //tpd not found, continue search
         abs_tpd_dir = NULL;
         Free(prefixed_file_path);
       }
-    }
+    } 
     //Error if tpd is not found in either search paths
     if(NULL == (const char*)abs_tpd_dir) {
       //Only write out the name in the error message (without .tpd)
@@ -1516,9 +1515,14 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
     ERROR("absolute TPD directory could not be retrieved from %s", (const char*)tpd_dir);
     return TPD_FAILED;
   }
-  autostring tpd_filename(get_file_from_path(p_tpd_name));
+  autostring tpd_filename(get_file_from_path(*p_tpd_name));
   autostring abs_tpd_name(compose_path_name(abs_tpd_dir, tpd_filename));
-
+  
+  if (local_optind == 0) {
+    Free(const_cast<char*>(*p_tpd_name));
+    *p_tpd_name = mcopystr((const char*)abs_tpd_name);
+  }
+    
   if (seen_tpd_files.has_key(abs_tpd_name)) {
     ++*seen_tpd_files[abs_tpd_name];
     return TPD_SKIPPED; // nothing to do
@@ -1541,9 +1545,9 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
 
   vector<char> base_files; // values Malloc'd but we pass them to the caller
 
-  XmlDoc doc(xmlParseFile(p_tpd_name));
+  XmlDoc doc(xmlParseFile(*p_tpd_name));
   if (doc == NULL) {
-    fprintf(stderr, "Error: unable to parse file \"%s\"\n", p_tpd_name);
+    fprintf(stderr, "Error: unable to parse file \"%s\"\n", *p_tpd_name);
     return TPD_FAILED;
   }
 
@@ -1557,9 +1561,9 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
       expstring_t xsd_file_name = mprintf("%s%setc/xsd/TPD.xsd", ttcn3_dir, ends_with_slash?"":"/");
       autostring xsd_file_name_as(xsd_file_name);
       if (get_path_status(xsd_file_name)==PS_FILE) {
-        if (validate_tpd(doc, p_tpd_name, xsd_file_name)) {
+        if (validate_tpd(doc, *p_tpd_name, xsd_file_name)) {
           tpd_is_valid = true;
-          NOTIFY("TPD file `%s' validated successfully with schema file `%s'", p_tpd_name, xsd_file_name);
+          NOTIFY("TPD file `%s' validated successfully with schema file `%s'", *p_tpd_name, xsd_file_name);
         }
       } else {
         ERROR("Cannot find XSD for schema for validation of TPD on path `%s'", xsd_file_name);
@@ -1607,6 +1611,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
       projGenHelper.setToplevelProjectName(*p_project_name);
       ProjectDescriptor* projDesc = projGenHelper.getTargetOfProject(*p_project_name);
       if (projDesc) projDesc->setProjectAbsTpdDir((const char*)abs_tpd_dir);
+      projGenHelper.insertAndCheckProjectName((const char*)abs_tpd_name, *p_project_name);
     }
   }
   
@@ -1841,7 +1846,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
   if (projDesc) {
     projDesc->setProjectAbsWorkingDir((const char*)proj_abs_workdir);
     projDesc->setProjectWorkingDir(real_workdir);
-    projDesc->setTPDFileName(p_tpd_name);
+    projDesc->setTPDFileName(*p_tpd_name);
   }
 
   /////////////////////////////////////////////////////////////////////////////
@@ -2925,7 +2930,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
 
         ProjectDescriptor* projDesc = projGenHelper.getTargetOfProject(*p_project_name);
         if (projDesc) projDesc->addToReferencedProjects(name);
-         
+        
         const char *my_actcfg = NULL;
         int my_argc = 0;
         char *my_args[] = { NULL };
@@ -2982,7 +2987,8 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
           }
         }
       
-        tpd_result success = process_tpd_internal((const char*)abs_projectLocationURI, tpdName_loc,
+        const char* abs_projectLocationURIchar = abs_projectLocationURI.extract();
+        tpd_result success = process_tpd_internal(&abs_projectLocationURIchar, tpdName_loc,
           my_actcfg, file_list_path, &my_argc, &my_argv, &my_free_argv, &my_optind, &my_ets, &my_proj_name,
           &my_gflag, &my_sflag, &my_cflag, &my_aflag, preprocess, &my_Rflag, &my_lflag,
           &my_mflag, &my_Pflag, &my_Lflag, recursive, force_overwrite, gen_only_top_level, NULL, &sub_proj_abs_work_dir,
@@ -2997,7 +3003,14 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
           search_paths, n_search_paths, makefileScript, all_configs);
         
         autostring sub_proj_abs_work_dir_as(sub_proj_abs_work_dir); // ?!
-
+        abs_projectLocationURI = abs_projectLocationURIchar;
+        if (get_config_mode) {
+          if (!projGenHelper.insertAndCheckProjectName((const char*)abs_projectLocationURI, name)) {
+            ERROR("In project `%s', the referenced project `%s's name attribute should be the same as the referenced project's name.",
+              *p_tpd_name, (const char*)abs_projectLocationURI);
+          }
+        }
+        
         if (success == TPD_SUCCESS && !get_config_mode) {
           my_actcfg = get_act_config(required_configs, my_proj_name);
           if (recursive) { // call ttcn3_makefilegen on referenced project's tpd file
@@ -3195,8 +3208,8 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
   }
   // Print the TPD too.
   if (*p_Pflag) {
-    autostring dir_part(get_dir_from_path(p_tpd_name));
-    autostring file_part(get_file_from_path(p_tpd_name));
+    autostring dir_part(get_dir_from_path(*p_tpd_name));
+    autostring file_part(get_file_from_path(*p_tpd_name));
     if (*p_aflag) {
       puts((const char *)abs_tpd_name);
     } else {
@@ -3253,10 +3266,6 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
     Free(const_cast<char*>(folders.get_nth_elem(i)));
   }
   folders.clear();
-  
-  if(free_name) {
-    Free(const_cast<char*>(p_tpd_name));
-  }
 
   excluded_files.clear();
   excluded_folders.clear();
@@ -3264,6 +3273,6 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
 
   xmlCleanupParser();
   // ifdef debug
-    xmlMemoryDump();
+  xmlMemoryDump();
   return result;
 }
diff --git a/compiler2/xpather.h b/compiler2/xpather.h
index 5716c0b68..f23e1d9cf 100644
--- a/compiler2/xpather.h
+++ b/compiler2/xpather.h
@@ -270,7 +270,7 @@ extern "C"
 #else
 enum
 #endif
-tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
+tpd_result process_tpd(const char **p_tpd_name, const char *actcfg,
   const char *file_list_path,
   int *argc, char ***argv, boolean* p_free_argv,
   int *optind, char **ets_name, char **project_name,
diff --git a/regression_test/compileonly/mfgen-tpd/Makefile b/regression_test/compileonly/mfgen-tpd/Makefile
index dc00192ef..51ec56f60 100644
--- a/regression_test/compileonly/mfgen-tpd/Makefile
+++ b/regression_test/compileonly/mfgen-tpd/Makefile
@@ -32,7 +32,7 @@ MAKEPROG := ${MAKE}
 DIRLIST := buildconfig_param invalid_buildconfig_param invalid_buildconfig_tpd \
 	HP79745 HQ56829 HQ56834 HQ56848 library HR30356 flagTest HR30365 dependency_check \
 	required_config required_config_v2  disablePredefinedExternalFolder \
-	makefileScript
+	makefileScript diff_tpd_name_error
 
 ifdef DYN
 DIRS += required_config_v3 splitting compile_once
diff --git a/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/Makefile b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/Makefile
new file mode 100644
index 000000000..67897daf6
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/Makefile
@@ -0,0 +1,46 @@
+##############################################################################
+# Copyright (c) 2000-2017 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd 
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -r -c -W -g 2>&1 | tee output
+
+CheckTpd: BuildTpd
+	if [ `grep -c "c.tpd's name attribute should be the same as the referenced project's name" ./output` -ne 2 ]; \
+	then echo "Makefilegen different tpd name in referenced project test failed: Overall verdict: fail" && exit 1; fi
+	if [ `grep -c "b.tpd's name attribute should be the same as the referenced project's name" ./output` -ne 1 ]; \
+	then echo "Makefilegen different tpd name in referenced project test failed: Overall verdict: fail" && exit 1; fi
+	if [ `grep -c "a.tpd's name attribute should be the same as the referenced project's name" ./output` -ne 1 ]; \
+	then echo "Makefilegen different tpd name in referenced project test failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf output a_binDefault b_binDefault c_binDefault
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/a.tpd b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/a.tpd
new file mode 100644
index 000000000..02130b979
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/a.tpd
@@ -0,0 +1,51 @@
+<!--
+ Copyright (c) 2000-2017 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ReferencedProjects>
+    <ReferencedProject name="b2" projectLocationURI="b.tpd"/>
+    <ReferencedProject name="c2" projectLocationURI="c.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+        <ConfigurationRequirements>
+          <configurationRequirement>
+            <projectName>b2</projectName>
+            <requiredConfiguration>1</requiredConfiguration>
+          </configurationRequirement>
+          <configurationRequirement>
+            <projectName>c2</projectName>
+            <requiredConfiguration>1</requiredConfiguration>
+          </configurationRequirement>
+        </ConfigurationRequirements>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="a">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+        
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/b.tpd b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/b.tpd
new file mode 100644
index 000000000..19cf545fd
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/b.tpd
@@ -0,0 +1,51 @@
+<!--
+ Copyright (c) 2000-2017 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>b</ProjectName>
+  <ReferencedProjects>
+    <ReferencedProject name="c2" projectLocationURI="c.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+         <ConfigurationRequirements>
+          <configurationRequirement>
+            <projectName>c</projectName>
+            <requiredConfiguration>1</requiredConfiguration>
+          </configurationRequirement>
+        </ConfigurationRequirements>
+      </ProjectProperties>
+    </Configuration>
+  <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>bin1</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+         <ConfigurationRequirements>
+          <configurationRequirement>
+            <projectName>c</projectName>
+            <requiredConfiguration>1</requiredConfiguration>
+          </configurationRequirement>
+        </ConfigurationRequirements>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/c.tpd b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/c.tpd
new file mode 100644
index 000000000..7ef7d99bf
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/diff_tpd_name_error/c.tpd
@@ -0,0 +1,49 @@
+<!--
+ Copyright (c) 2000-2017 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>c</ProjectName>
+  <ReferencedProjects>
+    <ReferencedProject name="a2" projectLocationURI="a.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>binDefault</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>binDefault</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>bin1</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="2">
+      <ProjectProperties>
+        <MakefileSettings>
+          <targetExecutable>bin2</targetExecutable>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin2</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/search_paths/main/Main.tpd b/regression_test/compileonly/mfgen-tpd/search_paths/main/Main.tpd
index 8dafb78ca..40011218b 100644
--- a/regression_test/compileonly/mfgen-tpd/search_paths/main/Main.tpd
+++ b/regression_test/compileonly/mfgen-tpd/search_paths/main/Main.tpd
@@ -11,7 +11,7 @@
   <ProjectName>Main</ProjectName>
   <ReferencedProjects>
     <ReferencedProject name="DepTpd1" projectLocationURI="../dep1/Test1/DepTpd1.tpd" />
-    <ReferencedProject name="Second" tpdName="DepTpd2.tpd" projectLocationURI="../bad/path/Test.tpd" />
+    <ReferencedProject name="DepTpd2" tpdName="DepTpd2.tpd" projectLocationURI="../bad/path/Test.tpd" />
     <ReferencedProject name="DepTpd3" projectLocationURI="../bad/path/Test.tpd" />
   </ReferencedProjects>
   <Folders>
-- 
GitLab