Considering your situation I believe bear spray is your best option. If you still feel the need for packing a gun I would recommend a shotgun loaded with buck shot. Very few people (myself included) can shoot a pistol accurately enough to stop a charging bear. A 12 gauge with the barrell sawed to minimum length can be attached to a backpack quite easily. If you are in an uncomfortable situation fire a round into the air. The animals reaction will let you know what your next move will be.