Hello,
João Pedro Malhado, le lun. 31 août 2026 13:32:27 +0100, a ecrit:
> --- dillo-3.3.0.orig/src/dilloc.c
> +++ dillo-3.3.0/src/dilloc.c
> @@ -104,9 +104,21 @@ connect_given_pid(int *sock, const char
> static int
> find_working_socket(int *sock)
> {
> - char ctlpath[PATH_MAX];
> - if (snprintf(ctlpath, PATH_MAX, "%s/.dillo/ctl", dGethomedir()) >=
> PATH_MAX) {
> - fprintf(stderr, "path too long\n");
> + int sz = snprintf(NULL, 0, "%s/.dillo/ctl", dGethomedir());
> + if (sz <= 0) {
> + fprintf(stderr, "path size error\n");
> + return -1;
> + }
> +
> + char *ctlpath = (char *) malloc(sz+1);
> + if (ctlpath == NULL) {
> + fprintf(stderr, "memory allocation error\n");
> + return -1;
> + }
If you are to malloc, better simply use asprintf ;)
Samuel
> +
> + if (snprintf(ctlpath, sz, "%s/.dillo/ctl", dGethomedir()) <= 0) {
> + fprintf(stderr, "path copy error\n");
> + free(ctlpath);
> return -1;
> }
>
> @@ -116,10 +128,11 @@ find_working_socket(int *sock)
> fprintf(stderr, "error: cannot open %s directory: %s\n",
> ctlpath, strerror(errno));
> fprintf(stderr, "hint: is dillo running?\n");
> + free(ctlpath);
> return -1;
> }
>
> - int found_pid = 0;
> + int found_pid = 0;
> struct sockaddr_un addr;
> addr.sun_family = AF_UNIX;
>
> @@ -136,6 +149,7 @@ find_working_socket(int *sock)
> #define LEN ((int) sizeof(addr.sun_path))
> if (snprintf(addr.sun_path, LEN, "%s/%s", ctlpath, num) >= LEN) {
> fprintf(stderr, "pid path too long\n");
> + free(ctlpath);
> return -1;
> }
> #undef LEN
> @@ -143,6 +157,7 @@ find_working_socket(int *sock)
> int fd;
> if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
> fprintf(stderr, "socket() failed: %s\n", strerror(errno));
> + free(ctlpath);
> return -1;
> }
>
> @@ -170,11 +185,13 @@ find_working_socket(int *sock)
>
> if (fd != -1 && dClose(fd) != 0) {
> fprintf(stderr, "cannot close fd: %s", strerror(errno));
> + free(ctlpath);
> return -1;
> }
> }
>
> closedir(dp);
> + free(ctlpath);
>
> if (found_pid == 1)
> return 0;
--
Samuel
Fatal Error: Found [MS-Windows] System -> Repartitioning Disk for Linux...
(By [email protected], Christopher Browne)