| 1281 | static char invalid_filename_char[] = {':', '/', '\\', '?', '%', '*', '<', '>', '"', '|', '\r', '\n', '\t'}; |
| 1282 | |
| 1283 | void Console::commandUpload(socket_native_type fd) |
| 1284 | { |
| 1285 | ssize_t n, rc; |
| 1286 | char buf[512] = {0}; |
| 1287 | char c = 0; |
| 1288 | char* ptr = buf; |
| 1289 | // read file name |
| 1290 | for (n = 0; n < sizeof(buf) - 1; n++) |
| 1291 | { |
| 1292 | if ((rc = recv(fd, &c, 1, 0)) == 1) |
| 1293 | { |
| 1294 | for (char x : invalid_filename_char) |
| 1295 | { |
| 1296 | if (c == x) |
| 1297 | { |
| 1298 | const char err[] = "upload: invalid file name!\n"; |
| 1299 | Console::Utility::sendToConsole(fd, err, strlen(err)); |
| 1300 | return; |
| 1301 | } |
| 1302 | } |
| 1303 | if (c == ' ') |
| 1304 | { |
| 1305 | break; |
| 1306 | } |
| 1307 | *ptr++ = c; |
| 1308 | } |
| 1309 | else if (rc == 0) |
| 1310 | { |
| 1311 | break; |
| 1312 | } |
| 1313 | else if (errno == EINTR) |
| 1314 | { |
| 1315 | continue; |
| 1316 | } |
| 1317 | else |
| 1318 | { |
| 1319 | break; |
| 1320 | } |
| 1321 | } |
| 1322 | *ptr = 0; |
| 1323 | |
| 1324 | static std::string writablePath = FileUtils::getInstance()->getWritablePath(); |
| 1325 | std::string filepath = writablePath + std::string(buf); |
| 1326 | |
| 1327 | auto fs = FileUtils::getInstance()->openFileStream(filepath, IFileStream::Mode::WRITE); |
| 1328 | if (!fs) |
| 1329 | { |
| 1330 | const char err[] = "can't create file!\n"; |
| 1331 | Console::Utility::sendToConsole(fd, err, strlen(err)); |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | while (true) |
| 1336 | { |
| 1337 | char data[4]; |
| 1338 | for (int i = 0; i < 4; i++) |
| 1339 | { |
| 1340 | data[i] = '='; |
nothing calls this directly
no test coverage detected