]> granicus.if.org Git - php/commitdiff
stat execution context and check it is a regular file or symlink
authorkrakjoe <joe.watkins@live.co.uk>
Sat, 16 Nov 2013 21:23:14 +0000 (21:23 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sat, 16 Nov 2013 21:23:14 +0000 (21:23 +0000)
phpdbg_prompt.c

index 91cc881d60ec408f84c03a17686855c3321d6080..e5276979e8bcaeda6c30f10e0647b6363bab3cee 100644 (file)
@@ -193,33 +193,43 @@ static PHPDBG_COMMAND(exec) /* {{{ */
                return SUCCESS;
        } else {
            if (param->type == STR_PARAM) {
-               if (PHPDBG_G(exec)) {
-                       phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
-                       efree(PHPDBG_G(exec));
-                       PHPDBG_G(exec) = NULL;
-               }
+               struct stat sb;
+               
+               if (VCWD_STAT(param->str, &sb) != FAILURE) {
+                   if (sb.st_mode & S_IFREG|S_IFLNK) {
+                       if (PHPDBG_G(exec)) {
+                               phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
+                               efree(PHPDBG_G(exec));
+                               PHPDBG_G(exec) = NULL;
+                       }
        
-               if (PHPDBG_G(ops)) {
-                       phpdbg_notice("Destroying compiled opcodes");
-                       phpdbg_clean(0 TSRMLS_CC);
-               }
+                       if (PHPDBG_G(ops)) {
+                               phpdbg_notice("Destroying compiled opcodes");
+                               phpdbg_clean(0 TSRMLS_CC);
+                       }
 
-               PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
+                       PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
 
-               if (!PHPDBG_G(exec)) {
-                       phpdbg_error("Cannot get real file path");
-                       return FAILURE;
-               }
+                       if (!PHPDBG_G(exec)) {
+                               phpdbg_error("Cannot get real file path");
+                               return FAILURE;
+                       }
 
-               PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
+                       PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
 
-               phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
+                       phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
+                       
+                   } else {
+                       phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
+                   }
+               } else {
+                   phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
+               }
            } else {
                phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
            }
        }
        
-       
        return SUCCESS;
 } /* }}} */