* Helper to create a temporary file. * * @param path_out An output pointer for the filename. Caller should free. * * @return 0 on success, -1 for file open error, or -2 for write error. */
| 31 | * @return 0 on success, -1 for file open error, or -2 for write error. |
| 32 | */ |
| 33 | static int create_temp_file(char **path_out) |
| 34 | { |
| 35 | int fd; |
| 36 | int rv; |
| 37 | char *path; |
| 38 | mode_t umask_save; |
| 39 | |
| 40 | #if defined(__FreeBSD__) |
| 41 | #define P_tmpdir "/tmp" |
| 42 | #endif |
| 43 | *path_out = NULL; |
| 44 | path = strdup(P_tmpdir "/flashrom.XXXXXX"); |
| 45 | /* Set the umask before mkstemp for security considerations. */ |
| 46 | umask_save = umask(077); |
| 47 | fd = mkstemp(path); |
| 48 | umask(umask_save); |
| 49 | if (fd < 0) { |
| 50 | rv = -1; |
| 51 | goto fail; |
| 52 | } |
| 53 | |
| 54 | close(fd); |
| 55 | *path_out = path; |
| 56 | |
| 57 | return 0; |
| 58 | fail: |
| 59 | free(path); |
| 60 | return rv; |
| 61 | } |
| 62 | |
| 63 | static int run_flashrom(const char *const argv[]) |
| 64 | { |
no test coverage detected