Skip to contentSkip to conversation

Bugfix for tools/blktap/lib/xs_api.c (convert_dev_name_to_num)

PATCH In review George Shuklin 2 participants 3 messages Sep 23, 2010 – Sep 24, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bugfix for tools/blktap/lib/xs_api.c (convert_dev_name_to_num)

I rewrote function convert_dev_name_to_num from
tools/blktap/lib/xs_api.c

Difference:

All code in loops has been converted from ..perverted for+while code to pure for. sizeof for char[]="..." will works faster, than strlen(string), strange *pte++ have been removed, *p++ changed to p+1 in function calls.

Second change more disputable: I change code:

ret = (majors[i/2]*256) + atoi(p);

to

ret = (majors[i/2]*256) + isdigit(p[1]) ? atoi(p) : 0;

I believe it will clear out undefined behavior to atoi when it called with non-convertible value (like letter or \x0).

I have not access to commits to hg, so diff in attachment for freshest xen-unstable.hg.

I think this patch can be apply to xen 3.4 too, where I found this bug early.

---
wBR, George.

45a46

Quoted 1 line

#include <ctype.h>

213c214
< char *p, *ptr;
---

Quoted 1 line
	char *p;

220c221
< char *alpha = "abcdefghijklmnop";
---

Quoted 1 line
	char alpha[] = "abcdefghijklmnop";

224,225c225,226
< for(i = 0, ptr = alpha; i < strlen(alpha); i++) {
< if(*ptr == *p)
---

Quoted 2 lines
		for(i = 0 ; i < sizeof(alpha)/sizeof(char); i++) {
			if(alpha[i] == *p)

227d227
< *ptr++;
229,230c229
< *p++;
< ret = BASE_DEV_VAL + (16*i) + atoi(p);
---

Quoted 1 line
		ret = BASE_DEV_VAL + (16*i) + isdigit(p[1]) ? atoi(p+1) : 0;

233,235c232,234
< for (i = 0, ptr = alpha; i < strlen(alpha); i++) {
< if(*ptr == *p) break;
< *ptr++;
---

Quoted 3 lines
		for(i = 0 ; i < sizeof(alpha)/sizeof(char); i++) {
			if(alpha[i] == *p)
				break;

237,238c236
< *p++;
< ret = (majors[i/2]*256) + atoi(p);
---

Quoted 1 line
		ret = (majors[i/2]*256) + isdigit(p[1]) ? atoi(p) : 0;

242,244c240,242
< for(i = 0, ptr = alpha; i < strlen(alpha); i++) {
< if(*ptr == *p) break;
< *ptr++;
---

Quoted 3 lines
		for(i = 0 ; i < sizeof(alpha)/sizeof(char); i++) {
			if(alpha[i] == *p) 
				break;

246,247c244
< *p++;
< ret = (202*256) + (16*i) + atoi(p);
---

Quoted 1 line
		ret = (202*256) + (16*i) + isdigit(p[1]) ? atoi(p) : 0;

251c248
< ret = atoi(p);
---

Quoted 1 line
		ret = isdigit(*p) ? atoi(p):0;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

George Shuklin writes ("[Xen-devel] [patch] Bugfix for tools/blktap/lib/xs_api.c (convert_dev_name_to_num)"):

Quoted 2 lines

I rewrote function convert_dev_name_to_num from
tools/blktap/lib/xs_api.c

Thanks but I'm afraid I don't think your patch is either a good idea or suitable.

Ian.

#2 lore raw

Well, I do not insist, but could you explain reason of using construction like *p++; or using atoi to arbitrary string?

В Птн, 24/09/2010 в 16:30 +0100, Ian Jackson пишет:

Quoted 8 lines

George Shuklin writes ("[Xen-devel] [patch] Bugfix for tools/blktap/lib/xs_api.c (convert_dev_name_to_num)"):

Quoted 2 lines

I rewrote function convert_dev_name_to_num from
tools/blktap/lib/xs_api.c

Thanks but I'm afraid I don't think your patch is either a good idea or suitable.

Ian.