stan-dev / stan-dev/math

Default constructor to system_functor leaves raw pointer uninitialized (UB if read)

Open
#829 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Description:

InSTAN_MATH_REV_MAT_FUNCTOR_ALGEBRA_SYSTEM_HPP, we have:

struct system_functor {
  F f_;
  Eigen::Matrix<T0, Eigen::Dynamic, 1> x_;
  Eigen::Matrix<T1, Eigen::Dynamic, 1> y_;
  std::vector<double> dat_;
  std::vector<int> dat_int_;
  std::ostream* msgs_;

  system_functor() {}

  system_functor(const F& f, const Eigen::Matrix<T0, Eigen::Dynamic, 1>& x,
                 const Eigen::Matrix<T1, Eigen::Dynamic, 1>& y,
                 const std::vector<double>& dat,
                 const std::vector<int>& dat_int, std::ostream* msgs)
      : f_(f), x_(x), y_(y), dat_(dat), dat_int_(dat_int), msgs_(msgs) {}

It seems like the default constructor should initialize msgs_ to nullptr to avoid msgs_ being some random value in the best case? This is UB if the pointer is either read or dereferenced.

Current Version:

v2.17.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open STAN_MATH_REV_MAT_FUNCTOR_ALGEBRA_SYSTEM_HPP and inspect the default constructor of system_functor. Ensure msgs_ has a defined null state when that constructor is used, then run the relevant existing test suite or build checks to confirm the change does not break compilation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.