]> git.saurik.com Git - apple/xnu.git/blobdiff - pexpert/gen/bootargs.c
xnu-4903.241.1.tar.gz
[apple/xnu.git] / pexpert / gen / bootargs.c
index 33a8db7741e7693dcdfca07571d2afb18e986bc3..754513a5cb09e9fae8e68c99efa079bcfb7247ef 100644 (file)
@@ -32,7 +32,9 @@ typedef boolean_t (*argsep_func_t) (char c);
 
 static boolean_t isargsep( char c);
 static boolean_t israngesep( char c);
+#ifndef CONFIG_EMBEDDED
 static int argstrcpy(char *from, char *to);
+#endif
 static int argstrcpy2(char *from,char *to, unsigned maxlen);
 static int argnumcpy(long long val, void *to, unsigned maxlen);
 static int getval(char *s, long long *val, argsep_func_t issep, boolean_t skip_equal_sign);
@@ -57,6 +59,10 @@ PE_parse_boot_arg(
 {
        int max_len = -1;
 
+#if CONFIG_EMBEDDED
+       /* Limit arg size to 4 byte when no size is given */
+       max_len = 4;
+#endif
 
        return PE_parse_boot_argn(arg_string, arg_ptr, max_len);
 }
@@ -79,6 +85,9 @@ PE_parse_boot_argn_internal(
        args = PE_boot_args();
        if (*args == '\0') return FALSE;
 
+#ifdef CONFIG_EMBEDDED
+       if (max_len == -1) return FALSE;
+#endif
 
        arg_found = FALSE;
 
@@ -105,9 +114,14 @@ PE_parse_boot_argn_internal(
                        goto gotit;
 
                if (arg_boolean) {
-                       if (!force_string){
-                               argnumcpy(1, arg_ptr, max_len);
-                               arg_found = TRUE;
+                       if (!force_string) {
+                               if (max_len > 0) {
+                                       argnumcpy(1, arg_ptr, max_len);/* max_len of 0 performs no copy at all*/
+                                       arg_found = TRUE;
+                               }
+                               else if (max_len == 0) {        
+                                       arg_found = TRUE;
+                               }
                        }
                        break;
                } else {
@@ -119,23 +133,41 @@ PE_parse_boot_argn_internal(
                        }
                        if ('_' == *arg_string) /* Force a string copy if the argument name begins with an underscore */
                        {
-                               int hacklen = 17 > max_len ? 17 : max_len;
-                               argstrcpy2 (++cp, (char *)arg_ptr, hacklen - 1); /* Hack - terminate after 16 characters */
-                               arg_found = TRUE;
+                               if (max_len > 0) {
+                                       int hacklen = 17 > max_len ? 17 : max_len;
+                                       argstrcpy2 (++cp, (char *)arg_ptr, hacklen - 1); /* Hack - terminate after 16 characters */
+                                       arg_found = TRUE;
+                               }
+                               else if (max_len == 0) {
+                                       arg_found = TRUE;
+                               }
                                break;
                        }
                        switch ((force_string && *cp == '=') ? STR : getval(cp, &val, isargsep, FALSE))
                        {
                                case NUM:
-                                       argnumcpy(val, arg_ptr, max_len);
-                                       arg_found = TRUE;
+                                       if (max_len > 0) {
+                                               argnumcpy(val, arg_ptr, max_len);
+                                               arg_found = TRUE;
+                                       }
+                                       else if (max_len == 0) {
+                                               arg_found = TRUE;
+                                       }
                                        break;
                                case STR:
-                                       if(max_len > 0) //max_len of 0 performs no copy at all
-                                               argstrcpy2(++cp, (char *)arg_ptr, max_len - 1);
-                                       else if(max_len == -1) // unreachable on embedded
+                                       if (max_len > 0) {
+                                               argstrcpy2(++cp, (char *)arg_ptr, max_len - 1);/*max_len of 0 performs no copy at all*/
+                                               arg_found = TRUE;
+                                       }
+                                       else if (max_len == 0) {
+                                               arg_found = TRUE;
+                                       }
+#if !CONFIG_EMBEDDED
+                                       else if (max_len == -1) { /* unreachable on embedded */
                                                argstrcpy(++cp, (char *)arg_ptr);
-                                       arg_found = TRUE;
+                                               arg_found = TRUE;
+                                       }
+#endif
                                        break;
                        }
                        goto gotit;
@@ -187,6 +219,7 @@ israngesep(char c)
                return (FALSE);
 }
 
+#if !CONFIG_EMBEDDED
 static int
 argstrcpy(
        char *from,
@@ -201,6 +234,7 @@ argstrcpy(
        *to = 0;
        return(i);
 }
+#endif
 
 static int
 argstrcpy2(