Skip to content

Commit

Permalink
Catch more possible instances of passing NULL to memcpy.
Browse files Browse the repository at this point in the history
Actually fixes #1976.
  • Loading branch information
shlevy committed Mar 15, 2018
1 parent d25d9f7 commit cfdbfa6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1601,12 +1601,16 @@ static void prim_partition(EvalState & state, const Pos & pos, Value * * args, V
state.mkAttrs(v, 2);

Value * vRight = state.allocAttr(v, state.sRight);
state.mkList(*vRight, right.size());
memcpy(vRight->listElems(), right.data(), sizeof(Value *) * right.size());
auto rsize = right.size();
state.mkList(*vRight, rsize);
if (rsize)
memcpy(vRight->listElems(), right.data(), sizeof(Value *) * rsize);

Value * vWrong = state.allocAttr(v, state.sWrong);
state.mkList(*vWrong, wrong.size());
memcpy(vWrong->listElems(), wrong.data(), sizeof(Value *) * wrong.size());
auto wsize = wrong.size();
state.mkList(*vWrong, wsize);
if (wsize)
memcpy(vWrong->listElems(), wrong.data(), sizeof(Value *) * wsize);

v.attrs->sort();
}
Expand Down
1 change: 1 addition & 0 deletions src/libstore/download.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct CurlDownloader : public Downloader
if (readOffset == request.data->length())
return 0;
auto count = std::min(size * nitems, request.data->length() - readOffset);
assert(count);
memcpy(buffer, request.data->data() + readOffset, count);
readOffset += count;
return count;
Expand Down
1 change: 1 addition & 0 deletions src/libutil/hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Hash::Hash(const std::string & s, HashType type)
auto d = base64Decode(std::string(s, pos));
if (d.size() != hashSize)
throw BadHash("invalid base-64 hash '%s'", s);
assert(hashSize);
memcpy(hash, d.data(), hashSize);
}

Expand Down

0 comments on commit cfdbfa6

Please sign in to comment.