Skip to content

Commit 703ef64

Browse files
committed
ym2651y: Fix potential buffer overflow for mfr_model/mfr_serial/mfr_model_opt
1 parent 8a91f3a commit 703ef64

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

packages/base/any/kernels/modules/ym2651y.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev)
860860
goto exit;
861861
}
862862

863+
buf = min_t(u8, buf, ARRAY_SIZE(data->mfr_model)-2);
863864
status = ym2651y_read_block(client, command, data->mfr_model, buf+1);
864865
data->mfr_model[buf+1] = '\0';
865866

@@ -883,6 +884,7 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev)
883884
goto exit;
884885
}
885886

887+
buf = min_t(u8, buf, ARRAY_SIZE(data->mfr_model_opt)-2);
886888
status = ym2651y_read_block(
887889
client, command, data->mfr_model_opt, buf+1);
888890

@@ -921,13 +923,10 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev)
921923
goto exit;
922924
}
923925

926+
buf = min_t(u8, buf, ARRAY_SIZE(data->mfr_serial)-2);
924927
status = ym2651y_read_block(client, command, data->mfr_serial, buf+1);
925-
if (data->mfr_serial[0] < ARRAY_SIZE(data->mfr_serial)-2) {
926-
data->mfr_serial[data->mfr_serial[0] + 1] = '\0';
927-
}
928-
else {
929-
data->mfr_serial[ARRAY_SIZE(data->mfr_serial)-1] = '\0';
930-
}
928+
929+
data->mfr_serial[buf+1] = '\0';
931930

932931
if (status < 0) {
933932
dev_dbg(&client->dev, "reg %d, err %d\n", command, status);

0 commit comments

Comments
 (0)