This paper studies the legitimacy of listed companies from the perspective of violation. We use the violation data of all A-share non-financial listed companies in Shanghai and Shenzhen from 2006 to 2019 and look at the relationship between corporate violation and charitable donation, and the possible influence of the regional institutional environment of enterprises and the degree of association between enterprises and government on the relationship between corporate violations and charitable donations. Compared with violations at the organizational level, enterprises with violations at the executive level are more active regarding charitable donations. The moderating effect indicates that the institutional environment level of the geographical region where the enterprise is located strengthens the negative relationship between the offending enterprise and charitable donation. After dividing into congenital and acquired government enterprise association, the congenital Government Enterprise Association has a strengthening effect on the charitable donation behavior of illegal enterprises.