Skip to content

Commit

Permalink
Merge pull request #17559 from king-11/longName
Browse files Browse the repository at this point in the history
User-facing errors for long filenames

[contributed by @king-11, reviewed by me]

add check to parse cmd files for ensuring they are under limit
Fixes #8758
  • Loading branch information
bradcray authored May 10, 2021
2 parents 074cb1c + dfa8d40 commit ed6dad3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
22 changes: 21 additions & 1 deletion compiler/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/parsing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/nameLength/aaa*
**/nameLength/longName.good
**/nameLength/longNameHelper.*
3 changes: 3 additions & 0 deletions test/parsing/errors/nameLength/CLEANFILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aaaaaa*
longName.good
longNameHelper*
1 change: 1 addition & 0 deletions test/parsing/errors/nameLength/longName.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "longNameHelper.chpl";
21 changes: 21 additions & 0 deletions test/parsing/errors/nameLength/longName.precomp
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/parsing/errors/nameLength/shortName.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
writeln("A short File Name");
1 change: 1 addition & 0 deletions test/parsing/errors/nameLength/shortName.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A short File Name

0 comments on commit ed6dad3

Please sign in to comment.