|
@@ -37,11 +37,9 @@ struct image_type script_image_type __image_type ( PROBE_NORMAL );
|
37
|
37
|
* @ret rc Return status code
|
38
|
38
|
*/
|
39
|
39
|
static int script_exec ( struct image *image ) {
|
40
|
|
- char cmdbuf[256];
|
41
|
40
|
size_t offset = 0;
|
42
|
|
- size_t remaining;
|
|
41
|
+ off_t eol;
|
43
|
42
|
size_t len;
|
44
|
|
- char *eol;
|
45
|
43
|
int rc;
|
46
|
44
|
|
47
|
45
|
/* Temporarily de-register image, so that a "boot" command
|
|
@@ -53,36 +51,29 @@ static int script_exec ( struct image *image ) {
|
53
|
51
|
|
54
|
52
|
while ( offset < image->len ) {
|
55
|
53
|
|
56
|
|
- /* Read up to cmdbuf bytes from script into buffer */
|
57
|
|
- remaining = ( image->len - offset );
|
58
|
|
- len = sizeof ( cmdbuf );
|
59
|
|
- if ( len > remaining )
|
60
|
|
- len = remaining;
|
61
|
|
- memset ( cmdbuf, 0, sizeof ( cmdbuf ) );
|
62
|
|
- copy_from_user ( cmdbuf, image->data, offset, len );
|
|
54
|
+ /* Find length of next line, excluding any terminating '\n' */
|
|
55
|
+ eol = memchr_user ( image->data, offset, '\n',
|
|
56
|
+ ( image->len - offset ) );
|
|
57
|
+ if ( eol < 0 )
|
|
58
|
+ eol = image->len;
|
|
59
|
+ len = ( eol - offset );
|
63
|
60
|
|
64
|
|
- /* Find end of line */
|
65
|
|
- eol = memchr ( cmdbuf, '\n', sizeof ( cmdbuf ) );
|
66
|
|
- if ( ! eol )
|
67
|
|
- eol = memchr ( cmdbuf, '\0', sizeof ( cmdbuf ) );
|
68
|
|
- if ( ! eol ) {
|
69
|
|
- DBG ( "Script line too long (max %zd bytes)\n",
|
70
|
|
- sizeof ( cmdbuf ) );
|
71
|
|
- rc = -ENOEXEC;
|
72
|
|
- goto done;
|
73
|
|
- }
|
|
61
|
+ /* Copy line, terminate with NUL, and execute command */
|
|
62
|
+ {
|
|
63
|
+ char cmdbuf[ len + 1 ];
|
74
|
64
|
|
75
|
|
- /* Mark end of line and execute command */
|
76
|
|
- *eol = '\0';
|
77
|
|
- DBG ( "$ %s\n", cmdbuf );
|
78
|
|
- if ( ( rc = system ( cmdbuf ) ) != 0 ) {
|
79
|
|
- DBG ( "Command \"%s\" failed: %s\n",
|
80
|
|
- cmdbuf, strerror ( rc ) );
|
81
|
|
- goto done;
|
|
65
|
+ copy_from_user ( cmdbuf, image->data, offset, len );
|
|
66
|
+ cmdbuf[len] = '\0';
|
|
67
|
+ DBG ( "$ %s\n", cmdbuf );
|
|
68
|
+ if ( ( rc = system ( cmdbuf ) ) != 0 ) {
|
|
69
|
+ DBG ( "Command \"%s\" failed: %s\n",
|
|
70
|
+ cmdbuf, strerror ( rc ) );
|
|
71
|
+ goto done;
|
|
72
|
+ }
|
82
|
73
|
}
|
83
|
74
|
|
84
|
75
|
/* Move to next line */
|
85
|
|
- offset += ( ( eol - cmdbuf ) + 1 );
|
|
76
|
+ offset += ( len + 1 );
|
86
|
77
|
}
|
87
|
78
|
|
88
|
79
|
rc = 0;
|