diff --git a/compiler/parser/parser.cpp b/compiler/parser/parser.cpp index f4ecb7aeb079..755571e44228 100644 --- a/compiler/parser/parser.cpp +++ b/compiler/parser/parser.cpp @@ -328,7 +328,27 @@ static void parseCommandLineFiles() { } while ((inputFileName = nthFilename(fileNum++))) { - if (isChplSource(inputFileName)) { + if (isChplSource(inputFileName)) + { + /* + Selection of 16 is did so as to provide + enough space for generating files like .tmp.obj + whose length is 8 so selection of double the required + */ + const size_t reductionMaxLength = 16; + /* + Ensure that all the files parsed don't exceed + (NAME_MAX - reductionMaxLength) e.g. 239 bytes on + unix and linux system. + */ + const size_t maxFileName = NAME_MAX - reductionMaxLength; + if (strlen(inputFileName) > maxFileName) + { + // error message to print placeholders for fileName and maxLength + const char *errorMessage = "%s, filename is longer than maximum allowed length of %d\n"; + // throwr error will concatenated messages + USR_FATAL(errorMessage, inputFileName, maxFileName); + } parseFile(inputFileName, MOD_USER, true, false); } } diff --git a/test/parsing/.gitignore b/test/parsing/.gitignore new file mode 100644 index 000000000000..08945468a403 --- /dev/null +++ b/test/parsing/.gitignore @@ -0,0 +1,3 @@ +**/nameLength/aaa* +**/nameLength/longName.good +**/nameLength/longNameHelper.* diff --git a/test/parsing/errors/nameLength/CLEANFILES b/test/parsing/errors/nameLength/CLEANFILES new file mode 100644 index 000000000000..1467b2e78f9e --- /dev/null +++ b/test/parsing/errors/nameLength/CLEANFILES @@ -0,0 +1,3 @@ +aaaaaa* +longName.good +longNameHelper* diff --git a/test/parsing/errors/nameLength/longName.chpl b/test/parsing/errors/nameLength/longName.chpl new file mode 100644 index 000000000000..3a23b4b2beb5 --- /dev/null +++ b/test/parsing/errors/nameLength/longName.chpl @@ -0,0 +1 @@ +require "longNameHelper.chpl"; diff --git a/test/parsing/errors/nameLength/longName.precomp b/test/parsing/errors/nameLength/longName.precomp new file mode 100755 index 000000000000..6d7da1e83902 --- /dev/null +++ b/test/parsing/errors/nameLength/longName.precomp @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +NAME_MAX=`getconf NAME_MAX /` +REDUCTIONMAXLENGTH=16 +LIMIT=$((NAME_MAX - REDUCTIONMAXLENGTH)) +OUTOFBOUND=$((LIMIT + 1)) +VAL="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +repeatChar() { + local input="$1" + local count="$2" + printf -v myString "%*s" "$count" + printf '%s\n' "${myString// /$input}" +} + +FILENAME=$(repeatChar a $OUTOFBOUND) +printf 'module LongName {\n\tfunc printSomething() {\n\t\twrite(%s); \n\t}\n}' "'Won't Compile'" > $VAL/$FILENAME.chpl +touch $VAL/$FILENAME.notest +printf 'require %s;' "'$FILENAME.chpl'" > $VAL/longNameHelper.chpl +touch $VAL/longNameHelper.notest +printf "error: %s, filename is longer than maximum allowed length of %d\n\n" $FILENAME.chpl $LIMIT > $VAL/longName.good diff --git a/test/parsing/errors/nameLength/shortName.chpl b/test/parsing/errors/nameLength/shortName.chpl new file mode 100644 index 000000000000..2ba0ea49daa7 --- /dev/null +++ b/test/parsing/errors/nameLength/shortName.chpl @@ -0,0 +1 @@ +writeln("A short File Name"); diff --git a/test/parsing/errors/nameLength/shortName.good b/test/parsing/errors/nameLength/shortName.good new file mode 100644 index 000000000000..4dc88bcf992f --- /dev/null +++ b/test/parsing/errors/nameLength/shortName.good @@ -0,0 +1 @@ +A short File Name