Question

In: Computer Science

Describe in detail any security problems that might exist in the following code and how you...

Describe in detail any security problems that might exist in the following code and how you might fix it. It has several problems:

char* src = malloc(18);

char* domain = “www.dogsarecool.nl”;

strncpy(src, domain, sizeof(domain))

Solutions

Expert Solution

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

When we declare a string in C, the last character is reserved for '\0' which is also known as the NULL character. It marks the end of the string.

So, if the length of char * array is n , then we can store up to ( n - 1 ) characters only as the last character is reserved for '\0'.

But in the above program, the size of src is of 18. So, upto 17 characters can be stored in the string src.

Now, the length of domain is 18 . Now, in the next statement we are copying all the characters of domain to src.

So, the function tries to copy 18 characters into the array src. So, it will overwrite the character '\0' and there will be no termination of the string. So, if we try o access the string, it will also consider the memory locations after the string as a part of the string which is a fatal error.

Kindly revert for any queries

Thanks.


Related Solutions

Will social security exist in 45 years? Why or why not? Describe how Social Security has...
Will social security exist in 45 years? Why or why not? Describe how Social Security has been one of the three legs of retirement planning.  
1. Identify any strategic groups that might exist in the industry. How does the intensity of...
1. Identify any strategic groups that might exist in the industry. How does the intensity of competi- tion differ across the strategic groups you have identified? My company is Pepsi Co 2.How dynamic is the industry in which your com- pany is based? Is there evidence that industry structure is reshaping competition, or has done so in the recent past? My COMPANY IS PEPSI CO.
I need a detail explanation of a Cyber Security Project you might have worked on or...
I need a detail explanation of a Cyber Security Project you might have worked on or know about or maybe any project topics or ideas would work.
Describe in detail the two kinds of options contracts that exist, also describe the advantages and...
Describe in detail the two kinds of options contracts that exist, also describe the advantages and disadvantages of each? making sure to include an example of each with an explanation of price differentials.
Describe in detail the two kinds of options contracts that exist, also describe the advantages and...
Describe in detail the two kinds of options contracts that exist, also describe the advantages and disadvantages of each? Making sure to include an example of each with an explanation of price differentials.
Describe the racial disparities that exist in the legal system . Describe problems faced by blacks...
Describe the racial disparities that exist in the legal system . Describe problems faced by blacks who attempt to use psychological evaluations for court cases, and explain what could be done to remedy these problems.
Find the solution of the following problems. Before doing these problems, you might want to review...
Find the solution of the following problems. Before doing these problems, you might want to review Exercise 3** on page 63: d.) xy" + y' = x, where y(1) = 1m and y'(1) = -1 (answer should be y(x) = 1/4 x2 - 3/2 ln(x) + 3/4) e.) (x-1)2y" + (x-1)y' - y = 0, where y(2) = 1, and y'(2) = 0 (answer should be: y(x) = 1/2 (x-1)-1 + x/2 - 1/2) **Exercise 3: The formula for a...
Identify three major laws and how they relate to Information security describe them in detail
Identify three major laws and how they relate to Information security describe them in detail
Describe in detail how a currency swap works. Be sure to discuss who might enter such...
Describe in detail how a currency swap works. Be sure to discuss who might enter such an agreement, why they might do so and the mechanics of settlement.
How would you rather address the problems in the social security program. Will you fix the...
How would you rather address the problems in the social security program. Will you fix the current problem that we have now or create a new system like a pre-funded system where everyone did have their own account that will be airmaked for them. Discuss any problems you see with either one of them and which one would you rather support.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT