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

test: fix printf formating #783

Merged
merged 1 commit into from
May 3, 2023
Merged

test: fix printf formating #783

merged 1 commit into from
May 3, 2023

Conversation

alfredh
Copy link
Contributor

@alfredh alfredh commented May 3, 2023

extracted from this patch:

#758

@sreimers sreimers merged commit 2516169 into main May 3, 2023
@sreimers sreimers deleted the test_fix_printf branch May 3, 2023 09:09
@alfredh
Copy link
Contributor Author

alfredh commented May 3, 2023

hi @maximilianfridrich

Could you please run your LLVM vararg tool after this, and see if it can find any issues ?

@maximilianfridrich
Copy link
Contributor

maximilianfridrich commented May 3, 2023

It did not find an issue. The tool is quite simple: It checks if the last non-variable argument to a variadic function is a non-constant string. If that is the case, it prints a warning.

So some of these warning are actually okay to ignore, but the origin of such a non-constant argument needs to be carefully checked by hand if it can be (partially) controlled by an external user. E.g. that was the case in the multipart sdp decoding function, because the boundary string is controlled externally and was then passed to the re_regex function.

Here is the core of the LLVM function pass:

void visitor(Function &F) {
  for (auto &BB : F) {
    for (auto &Ins : BB) {

      auto *CB = dyn_cast<CallBase>(&Ins);
      if (nullptr == CB) {
        continue;
      }
      // If CB is a direct function call then DirectInvoc will be not null.
      auto *DirectInvoc = CB->getCalledFunction();
      if (nullptr == DirectInvoc) {
        continue;
      }
      if (DirectInvoc->isVarArg()) {
        int LastIndex = DirectInvoc->arg_size() - 1;
        Value *LastArg = CB->getArgOperand(LastIndex);

        if (!isa<Constant>(LastArg) && !isa<ConstantDataSequential>(LastArg)) {
          errs()
              << "Warning: In function " << F.getName() << " calling function "
              << DirectInvoc->getName()
              << " where the last non-variable argument is not a constant "
                 "string\n";
        }
      }
    }
  }
}

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

Successfully merging this pull request may close these issues.

3 participants