|
1 |
| -#include <iostream> |
| 1 | +#include <iostream> |
2 | 2 | #include <vector>
|
3 | 3 | #include <fstream>
|
4 | 4 | #include <cstddef>
|
@@ -204,10 +204,26 @@ void process_append()
|
204 | 204 |
|
205 | 205 | // First level
|
206 | 206 | char a[1024] = {};
|
| 207 | + if (location >= sizeof(a)-1) // the array should contain at least contain a '-' and a null byte |
| 208 | + { |
| 209 | + cout << "Target " << targ << endl << "too long : Overflow" << endl; |
| 210 | + return; |
| 211 | + } |
207 | 212 | strncpy(a, targ.c_str(), location);
|
208 | 213 | strcat(a, "-");
|
209 | 214 | char temp[1024] = {};
|
| 215 | + if(appnd.length() >= sizeof(temp)) |
| 216 | + { |
| 217 | + cout << "Append value " << appnd << endl << "too long : Overflow" << endl; |
| 218 | + return; |
| 219 | + } |
210 | 220 | strncpy(temp, appnd.c_str(), appnd.length());
|
| 221 | + if((strlen(a)+strlen(temp) >=sizeof(a)) || (strlen(a)+targ.substr(location, targ.length() - location).length() >=sizeof(a))) |
| 222 | + { |
| 223 | + cout << "Can't concatenate target and append, strings too long : Overflow" << endl; |
| 224 | + return; |
| 225 | + } |
| 226 | + |
211 | 227 | strcat(a, temp);
|
212 | 228 | strcat(a, targ.substr(location, targ.length() - location).c_str());
|
213 | 229 | print_domain(string(a));
|
@@ -323,7 +339,22 @@ void process_prepend()
|
323 | 339 | string targ = *target;
|
324 | 340 | // First one
|
325 | 341 | char a[1024] = {};
|
| 342 | + if (prep.length() >= sizeof(a)-1) |
| 343 | + { |
| 344 | + cout << "Prepend " << prep << endl << "too long : Overflow" << endl; |
| 345 | + return; |
| 346 | + } |
326 | 347 | strncpy(a, prep.c_str(), prep.length());
|
| 348 | + if(targ.length()> 1024) // this is to prevent integer overflow in the check below |
| 349 | + { |
| 350 | + cout << "Target " << targ << endl << "is too long : Overflow" << endl; |
| 351 | + return; |
| 352 | + } |
| 353 | + if(strlen(a)+targ.length() >= sizeof(a)-1) |
| 354 | + { |
| 355 | + cout << "Can't concatenate target and prepend, strings too long : Overflow" << endl; |
| 356 | + return; |
| 357 | + } |
327 | 358 | strcat(a, targ.c_str());
|
328 | 359 |
|
329 | 360 | print_domain(string(a));
|
|
0 commit comments