Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible format string issue in Slim\Http\UploadedFile::moveTo() #2433

Closed
sjinks opened this issue May 8, 2018 · 3 comments
Closed

Possible format string issue in Slim\Http\UploadedFile::moveTo() #2433

sjinks opened this issue May 8, 2018 · 3 comments

Comments

@sjinks
Copy link

sjinks commented May 8, 2018

throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
throw new RuntimeException(sprintf('Error removing uploaded file %1s', $this->name));
throw new RuntimeException(sprintf('%1s is not a valid uploaded file', $this->file));
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));

According to the documentation, 1 and 2 in %1s and %2s are width specifiers (that is, the minimum length of the converted string).

That is, %1s will give the string with at least one character, %2s with at least to characters, that is:

> echo sprintf("Error moving uploaded file %1s to %2s", "a", "b");
Error moving uploaded file a to  b

But other than with empty or single letter file names, this is probably meaningless.

As far as I understand, the original intent was to facilitate internationalization to make sure that the first parameter is always the name of the source file, and the second one is the destination. If so, the correct syntax will be

sprintf('Error moving uploaded file %1$s to %2$s', $this->name, $targetPath)

E.g.,

> echo sprintf("Error moving uploaded file %1\$s to %2\$s\n", "file1", "file2");
Error moving uploaded file file1 to file2
> echo sprintf("Error moving uploaded file %2\$s to %1\$s\n", "file1", "file2");
Error moving uploaded file file2 to file1
@geggleto
Copy link
Member

I don't see an actual problem here?

llvdl added a commit to llvdl/Slim that referenced this issue Jul 9, 2018
@llvdl
Copy link
Contributor

llvdl commented Jul 9, 2018

It seems to be confusing. I think the author meant to use numbered placeholders, not padded strings. I propose just using plain placeholders (%s). I have added a PR.

@designermonkey
Copy link
Member

As the PR was merged to alter behaviour, and no more info or comments have been added by @sjinks, I'm closing this issue. If there is any more info, please add it and it can be reopened if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants