Skip to content

Commit 1afc0a0

Browse files
authored
Merge pull request #3 from danielmundi/master
Prevent buffer overflow and change process forking
2 parents db44eb5 + 861f705 commit 1afc0a0

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

Source/main.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void send_signal_to_python_process(int signal) {
9595
}
9696
}
9797
}
98+
else {
99+
log2file("no PID found");
100+
}
98101
}
99102

100103
pthread_t view_thread_id = 0;
@@ -109,7 +112,7 @@ void* threadfunc(char* arg) {
109112

110113
int load_python_view() {
111114
int ret;
112-
char* cmd = (char*)malloc(255);
115+
char* cmd = (char*)malloc(500);
113116
sprintf(cmd, "cd %s/BakeBit/Software/Python && python3 %s 2>&1 | tee /tmp/nanoled-python.log", workpath, python_file);
114117
ret = pthread_create(&view_thread_id, NULL, (void*)threadfunc,cmd);
115118
if(ret) {
@@ -144,7 +147,7 @@ int find_pid_by_name( char* ProcName, const char* proc_argument, int* foundpid)
144147
char exe [PATH_MAX+1];
145148
char path[PATH_MAX+1];
146149
char cmdline_path[PATH_MAX+1];
147-
char *cmdline = (char*)malloc(sizeof(CMDLINE_LENGTH+1));
150+
char *cmdline = (char*)malloc(sizeof(char)*(CMDLINE_LENGTH+1));
148151
int bufread;
149152
int len;
150153
int namelen;
@@ -292,21 +295,13 @@ int main(int argc, char** argv) {
292295
int i, n;
293296
char ch;
294297

295-
if (isAlreadyRunning() == 1) {
296-
exit(3);
297-
}
298-
299298
int ret = get_work_path(workpath, sizeof(workpath));
300299
if (ret != 0) {
301300
log2file("get_work_path str(errno) = %s\n", strerror(ret));
302301
return 1;
303302
}
304303
log2file("work_dir = %s\n", workpath);
305304

306-
daemonize( "nanohat-oled" );
307-
308-
sleep(3);
309-
310305
epfd = epoll_create(1);
311306
if (epfd < 0) {
312307
log2file("error creating epoll\n");

fpms.service.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Description=FPMS daemon responsible for OLED management
44
[Service]
55
ExecStart=@bindir@/oled-start
66
WorkingDirectory=@datadir@/fpms
7-
PIDfile=/var/run/nanohat-oled.pid
8-
Type=forking
97

108
[Install]
119
WantedBy=multi-user.target

0 commit comments

Comments
 (0)