Swift and Stack smashing protection

前端 未结 3 1195
灰色年华
灰色年华 2021-01-04 07:20

How to enable Stack Smashing Protection in pure swift application?

I did try to put \"-fstack-protector-all\" flag to Other C++ Flags under project build settings t

3条回答
  •  [愿得一人]
    2021-01-04 07:46

    I was also facing this in my 100% Swift project.

    Whenever I added -fstack-protector-all to the "Other C-Flags" Build Settings the flags did not show up in the binary as described in the other comments.

    What I did was to create an Objective-C Class…

    // DummyClassForSSP.h
    #import 
    
    NS_ASSUME_NONNULL_BEGIN
    
    @interface DummyClassForSSP : NSObject
    + (void)dummyCallSoFlagsShowUpInIPA;
    @end
    
    NS_ASSUME_NONNULL_END
    

    … added a dummy implementation …

    // DummyClassForSSP.m
    #import "DummyClassForSSP.h"
    
    @implementation DummyClassForSSP
    
    + (void)dummyCallSoFlagsShowUpInIPA {}
    
    @end
    

    … and called it from my AppDelegate.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    ....
    DummyClassForSSP.dummyCallSoFlagsShowUpInIPA()
    ...
    }
    

    After that the flags showed up as described.

提交回复
热议问题