Commit 8bfa79fcb81d2bdb043f60ab4171704467808b55
Committed by
Jeff Garzik
1 parent
a0cf733b33
Exists in
master
and in
4 other branches
libata: use ata_id_c_string()
There were several places where ATA ID strings are manually terminated and in some places possibly unterminated strings were passed to string functions which don't limit length like strstr(). This patch converts all of them over to ata_id_c_string(). Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Showing 6 changed files with 23 additions and 78 deletions Side-by-side Diff
drivers/ata/libata-core.c
... | ... | @@ -3325,35 +3325,20 @@ |
3325 | 3325 | { } |
3326 | 3326 | }; |
3327 | 3327 | |
3328 | -static int ata_strim(char *s, size_t len) | |
3329 | -{ | |
3330 | - len = strnlen(s, len); | |
3331 | - | |
3332 | - /* ATAPI specifies that empty space is blank-filled; remove blanks */ | |
3333 | - while ((len > 0) && (s[len - 1] == ' ')) { | |
3334 | - len--; | |
3335 | - s[len] = 0; | |
3336 | - } | |
3337 | - return len; | |
3338 | -} | |
3339 | - | |
3340 | 3328 | unsigned long ata_device_blacklisted(const struct ata_device *dev) |
3341 | 3329 | { |
3342 | - unsigned char model_num[ATA_ID_PROD_LEN]; | |
3343 | - unsigned char model_rev[ATA_ID_FW_REV_LEN]; | |
3344 | - unsigned int nlen, rlen; | |
3330 | + unsigned char model_num[ATA_ID_PROD_LEN + 1]; | |
3331 | + unsigned char model_rev[ATA_ID_FW_REV_LEN + 1]; | |
3345 | 3332 | const struct ata_blacklist_entry *ad = ata_device_blacklist; |
3346 | 3333 | |
3347 | - ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
3348 | - ata_id_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); | |
3349 | - nlen = ata_strim(model_num, sizeof(model_num)); | |
3350 | - rlen = ata_strim(model_rev, sizeof(model_rev)); | |
3334 | + ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
3335 | + ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); | |
3351 | 3336 | |
3352 | 3337 | while (ad->model_num) { |
3353 | - if (!strncmp(ad->model_num, model_num, nlen)) { | |
3338 | + if (!strcmp(ad->model_num, model_num)) { | |
3354 | 3339 | if (ad->model_rev == NULL) |
3355 | 3340 | return ad->horkage; |
3356 | - if (!strncmp(ad->model_rev, model_rev, rlen)) | |
3341 | + if (!strcmp(ad->model_rev, model_rev)) | |
3357 | 3342 | return ad->horkage; |
3358 | 3343 | } |
3359 | 3344 | ad++; |
drivers/ata/pata_ali.c
... | ... | @@ -153,11 +153,11 @@ |
153 | 153 | |
154 | 154 | static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) |
155 | 155 | { |
156 | - char model_num[ATA_ID_PROD_LEN]; | |
156 | + char model_num[ATA_ID_PROD_LEN + 1]; | |
157 | 157 | /* No DMA on anything but a disk for now */ |
158 | 158 | if (adev->class != ATA_DEV_ATA) |
159 | 159 | mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
160 | - ata_id_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
160 | + ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
161 | 161 | if (strstr(model_num, "WDC")) |
162 | 162 | return mask &= ~ATA_MASK_UDMA; |
163 | 163 | return ata_pci_default_filter(ap, adev, mask); |
drivers/ata/pata_hpt366.c
... | ... | @@ -151,23 +151,13 @@ |
151 | 151 | |
152 | 152 | static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) |
153 | 153 | { |
154 | - unsigned char model_num[ATA_ID_PROD_LEN]; | |
155 | - char *s; | |
156 | - unsigned int len; | |
154 | + unsigned char model_num[ATA_ID_PROD_LEN + 1]; | |
157 | 155 | int i = 0; |
158 | 156 | |
159 | - ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
160 | - s = &model_num[0]; | |
161 | - len = strnlen(s, sizeof(model_num)); | |
157 | + ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
162 | 158 | |
163 | - /* ATAPI specifies that empty space is blank-filled; remove blanks */ | |
164 | - while ((len > 0) && (s[len - 1] == ' ')) { | |
165 | - len--; | |
166 | - s[len] = 0; | |
167 | - } | |
168 | - | |
169 | - while(list[i] != NULL) { | |
170 | - if (!strncmp(list[i], s, len)) { | |
159 | + while (list[i] != NULL) { | |
160 | + if (!strcmp(list[i], model_num)) { | |
171 | 161 | printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n", |
172 | 162 | modestr, list[i]); |
173 | 163 | return 1; |
drivers/ata/pata_hpt37x.c
... | ... | @@ -349,23 +349,13 @@ |
349 | 349 | |
350 | 350 | static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) |
351 | 351 | { |
352 | - unsigned char model_num[ATA_ID_PROD_LEN]; | |
353 | - char *s; | |
354 | - unsigned int len; | |
352 | + unsigned char model_num[ATA_ID_PROD_LEN + 1]; | |
355 | 353 | int i = 0; |
356 | 354 | |
357 | - ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
358 | - s = &model_num[0]; | |
359 | - len = strnlen(s, sizeof(model_num)); | |
355 | + ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
360 | 356 | |
361 | - /* ATAPI specifies that empty space is blank-filled; remove blanks */ | |
362 | - while ((len > 0) && (s[len - 1] == ' ')) { | |
363 | - len--; | |
364 | - s[len] = 0; | |
365 | - } | |
366 | - | |
367 | - while(list[i] != NULL) { | |
368 | - if (!strncmp(list[i], s, len)) { | |
357 | + while (list[i] != NULL) { | |
358 | + if (!strcmp(list[i], model_num)) { | |
369 | 359 | printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n", |
370 | 360 | modestr, list[i]); |
371 | 361 | return 1; |
drivers/ata/pata_it821x.c
... | ... | @@ -531,22 +531,9 @@ |
531 | 531 | |
532 | 532 | static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev) |
533 | 533 | { |
534 | - unsigned char model_num[ATA_ID_PROD_LEN]; | |
535 | - char *s; | |
536 | - unsigned int len; | |
534 | + unsigned char model_num[ATA_ID_PROD_LEN + 1]; | |
537 | 535 | |
538 | - /* This block ought to be a library routine as it is in several | |
539 | - drivers now */ | |
540 | - | |
541 | - ata_id_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
542 | - s = &model_num[0]; | |
543 | - len = strnlen(s, sizeof(model_num)); | |
544 | - | |
545 | - /* ATAPI specifies that empty space is blank-filled; remove blanks */ | |
546 | - while ((len > 0) && (s[len - 1] == ' ')) { | |
547 | - len--; | |
548 | - s[len] = 0; | |
549 | - } | |
536 | + ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
550 | 537 | |
551 | 538 | if (adev->max_sectors > 255) |
552 | 539 | adev->max_sectors = 255; |
drivers/ata/pata_serverworks.c
... | ... | @@ -218,25 +218,18 @@ |
218 | 218 | static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) |
219 | 219 | { |
220 | 220 | const char *p; |
221 | - char model_num[ATA_ID_PROD_LEN]; | |
222 | - int len, i; | |
221 | + char model_num[ATA_ID_PROD_LEN + 1]; | |
222 | + int i; | |
223 | 223 | |
224 | 224 | /* Disk, UDMA */ |
225 | 225 | if (adev->class != ATA_DEV_ATA) |
226 | 226 | return ata_pci_default_filter(ap, adev, mask); |
227 | 227 | |
228 | 228 | /* Actually do need to check */ |
229 | - ata_id_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
230 | - /* Precuationary - why not do this in the libata core ?? */ | |
229 | + ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); | |
231 | 230 | |
232 | - len = strlen(model_num); | |
233 | - while ((len > 0) && (model_num[len - 1] == ' ')) { | |
234 | - len--; | |
235 | - model_num[len] = 0; | |
236 | - } | |
237 | - | |
238 | - for(i = 0; (p = csb_bad_ata100[i]) != NULL; i++) { | |
239 | - if (!strncmp(p, model_num, len)) | |
231 | + for (i = 0; (p = csb_bad_ata100[i]) != NULL; i++) { | |
232 | + if (!strcmp(p, model_num)) | |
240 | 233 | mask &= ~(0x1F << ATA_SHIFT_UDMA); |
241 | 234 | } |
242 | 235 | return ata_pci_default_filter(ap, adev, mask); |