Any ideas, what may be the possible bug in the following code:
1: public static int binarySearch(int[] a, int key) {
2: int low = 0;
3: int high = a.length - 1;
4:
5: while (low <= high) {
6: int mid = (low + high) / 2;
7: int midVal = a[mid];
8:
9: if (midVal < key)
10: low = mid + 1;
11: else if (midVal > key)
12: high = mid - 1;
13: else
14: return mid; // key found
15: }
16: return -(low + 1); // key not found.
17: }
Note: It is standard algo implemented in Java to sort ArrayList
Regards,
Sandeep
Secure Programming
With the FireWalls & a mammoth lock on gate, do you think the fort is secure?
No. The walls are weak and the daemons standing on gates are gullible.
We are here to learn breaking the walls and tricking the deamons, and to learn making them secure.
It not about certification bullshit.It's just about CODE. Lets start the drill.
"If you know the enemy and know yourself, your victory will not stand in doubt; if you know Heaven and know Earth, you may make your victory complete"
-Art of War
Friday, January 19, 2007
Monday, September 12, 2005
Tuesday, August 02, 2005
Simple Yet Common Again
int catvars(char *buf1, char *buf2, unsigned int len1,
unsigned int len2){
char mybuf[256];
if((len1 + len2) > 256){
return -1;
}
memcpy(mybuf, buf1, len1);
memcpy(mybuf + len1, buf2, len2);
do_some_stuff(mybuf);
return 0;
}
unsigned int len2){
char mybuf[256];
if((len1 + len2) > 256){
return -1;
}
memcpy(mybuf, buf1, len1);
memcpy(mybuf + len1, buf2, len2);
do_some_stuff(mybuf);
return 0;
}
Simple Yet Common
int myfunction(int *array, int len){
int *myarray, i;
myarray = malloc(len * sizeof(int));
if(myarray == NULL){
return -1;
}
for(i = 0; i < len; i++){
myarray[i] = array[i];
}
return myarray;
}
int *myarray, i;
myarray = malloc(len * sizeof(int));
if(myarray == NULL){
return -1;
}
for(i = 0; i < len; i++){
myarray[i] = array[i];
}
return myarray;
}
Tuesday, July 19, 2005
Spot the bug
Microsoft's guy is also hosting a blog where he will be posting the code and you have to find a bug.
Check this out: http://blogs.msdn.com/rsamona/
Thanks
Sandeep
Check this out: http://blogs.msdn.com/rsamona/
Thanks
Sandeep
Tuesday, July 05, 2005
Games
Ever played hacking games??
Check: http://quiz.ngsec.com/
It is pretty trivial..
Once you are done with it..Dont miss http://hackerslab.org
Amazing.
Check: http://quiz.ngsec.com/
It is pretty trivial..
Once you are done with it..Dont miss http://hackerslab.org
Amazing.
Friday, April 15, 2005
The temporary one!
void main()
{
FILE *fh = fopen("/tmp/ABC_my_junk_spot", "w+");
fprintf(fh, "hello..what are you looking at?");
fclose(fh);
}
Find out what is wrong with this piece of code?
How would you exploit this to gain root access if this code runs as root?
PS: The bar girls are like /tmp because
1. They are public property 2.They talk too much
{
FILE *fh = fopen("/tmp/ABC_my_junk_spot", "w+");
fprintf(fh, "hello..what are you looking at?");
fclose(fh);
}
Find out what is wrong with this piece of code?
How would you exploit this to gain root access if this code runs as root?
PS: The bar girls are like /tmp because
1. They are public property 2.They talk too much
Thursday, April 14, 2005
A unix teaser
I was no God.
I told her my password.
She ran to a unix terminal.
She logged in to my account.
Using 'passwd' she changed my password to whatever she wanted.
she checked if the password was changed. It really was.
When she came back, she fainted when she saw me using different password.
How could I do that?
TIP: It was a race condition
I told her my password.
She ran to a unix terminal.
She logged in to my account.
Using 'passwd' she changed my password to whatever she wanted.
she checked if the password was changed. It really was.
When she came back, she fainted when she saw me using different password.
How could I do that?
TIP: It was a race condition
Subscribe to:
Posts (Atom)