There is a law that protect donors of food who provide that food in good faith. Feeding America, the over-arching organization that provides hunger relief initiatives and information nationwide, has a great page of information on this law–the Good Samaritan Food Donation Act.
We often get questions about food dating as well. As a food pantry, we receive many donations of food that has a near date. The below link gives information about food dating.