Problem

The “beck” exploit. A popular web server supports a function named no2slash() whose purpos...

The “beck” exploit. A popular web server supports a function named no2slash() whose purpose is to collapse multiple / characters. For example, the string /d1///d2////d3/test.html collapses to /d1/d2/d3/test.html. The original algorithm was to repeatedly search for a / and copy the remainder of the string:

int n = name.length();int i = 1;while (i < n){  if ((c[i-1] == '/') && (c[i] == '/'))  {   for(int j = i+1; j < n; j++)     c[j-1] = c[j];    n--;  }  else i++;}

Unfortunately, this code can takes quadratic time (for example, if the string consists of the / character repeated n times). By sending multiple simultaneous requests with large numbers of / characters, a hacker could deluge the server and starve other processes for CPU time, thereby creating a denial-of-service attack. Develop a version of no2slash() that runs in linear time and does not allow for this type of attack.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 4.1