Skip to contentSkip to conversation

left shift of negative value in dcbp_set_pad_bits()

Drbd-dev David Butterfield 1 participant 1 message Jul 8, 2019 DRBD driver

lore
Share & tools
lore
#0 lore raw

This fixes a C undefined-behavior runtime error encountered by libubsan after gcc -fsanitize=undefined:
left shift of negative value in dcbp_set_pad_bits()

I mentioned this one before, but in the context of a boring compiler warning. The runtime undefined-behavior may make it more interesting.

drbd/drbd_main.c +0 -0
index 062c5ca1..16b4f02d 100644
@@ -1832,7 +1840,7 @@ static void dcbp_set_start(struct p_compressed_bm *p, int set)
 static void dcbp_set_pad_bits(struct p_compressed_bm *p, int n)
 {
	BUG_ON(n & ~0x7);

- p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4);
+ p->encoding = (p->encoding & (~0x7u << 4)) | (n << 4);
}

static int fill_bitmap_rle_bits(struct drbd_peer_device *peer_device,