If the owner of any stock drives any stock on the line of the track of any railway company or corporation, with intent to injure such company or corporation, and if said stock is killed or injured, the owner shall not receive any damages from the railroad company or corporation therefor, and shall be liable to such company or corporation for all damage such company or corporation may suffer in consequence of said act, and commits a class 6 felony and shall be punished as provided in section 18-1.3-401, C.R.S.; but nothing in this section shall be construed to prevent any person from allowing his or her stock to pasture on the lands adjacent to the line of such railroads or to drive his or her stock over or across any such track at suitable times and places.