Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/archivers/lha/files/patch-util.c
16147 views
1
--- src/util.c.orig 2000-10-04 14:57:38 UTC
2
+++ src/util.c
3
@@ -28,10 +28,10 @@ copyfile(f1, f2, size, crc_flg) /* retur
4
* append */
5
{
6
unsigned short xsize;
7
- char *buf;
8
+ unsigned char *buf;
9
long rsize = 0;
10
11
- if ((buf = (char *) malloc(BUFFERSIZE)) == NULL)
12
+ if ((buf = (unsigned char *) malloc(BUFFERSIZE)) == NULL)
13
fatal_error("virtual memory exhausted.\n");
14
crc = 0;
15
if ((crc_flg == 2 || crc_flg) && text_mode)
16
@@ -100,9 +100,7 @@ encode_stored_crc(ifp, ofp, size, origin
17
erreturns *filename */
18
/* ------------------------------------------------------------------------ */
19
unsigned char *
20
-convdelim(path, delim)
21
- unsigned char *path;
22
- unsigned char delim;
23
+convdelim(unsigned char *path, unsigned char delim)
24
{
25
unsigned char c;
26
unsigned char *p;
27
@@ -276,21 +274,27 @@ rmdir(path)
28
char *path;
29
{
30
int stat, rtn = 0;
31
- char *cmdname;
32
- if ((cmdname = (char *) malloc(strlen(RMDIRPATH) + 1 + strlen(path) + 1))
33
- == 0)
34
+ pid_t child;
35
+
36
+
37
+ /* XXX thomas: shell meta chars in path could exec commands */
38
+ /* therefore we should avoid using system() */
39
+ if ((child = fork()) < 0)
40
+ return (-1); /* fork error */
41
+ else if (child) { /* parent process */
42
+ while (child != wait(&stat)) /* ignore signals */
43
+ continue;
44
+ }
45
+ else { /* child process */
46
+ execl(RMDIRPATH, "rmdir", path, (char *) 0);
47
+ /* never come here except execl is error */
48
return (-1);
49
- strcpy(cmdname, RMDIRPATH);
50
- *(cmdname + strlen(RMDIRPATH)) = ' ';
51
- strcpy(cmdname + strlen(RMDIRPATH) + 1, path);
52
- if ((stat = system(cmdname)) < 0)
53
- rtn = -1; /* fork or exec error */
54
- else if (stat) { /* RMDIR command error */
55
- errno = EIO;
56
- rtn = -1;
57
}
58
- free(cmdname);
59
- return (rtn);
60
+ if (stat != 0) {
61
+ errno = EIO; /* cannot get error num. */
62
+ return (-1);
63
+ }
64
+ return (0);
65
}
66
67
/* ------------------------------------------------------------------------ */
68
69